1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 from os import F_OK, access, getcwd, path, sep
26 from numpy import array, asarray, exp, median, inf, log, save, std, sum, zeros
27 from minfx.generic import generic_minimise
28 from random import gauss
29 import re, math
30 from sys import version_info
31 from tempfile import mkdtemp, NamedTemporaryFile
32
33
34
35 from auto_analyses import relax_disp
36 from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep
37 from data_store import Relax_data_store; ds = Relax_data_store()
38 import dep_check
39 from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_ANALYTIC_CPMG, MODEL_LIST_FULL, MODEL_LIST_NUMERIC_CPMG, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03
40 from lib.errors import RelaxError
41 from lib.io import extract_data, get_file_path, open_read_file
42 from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file
43 from pipe_control.mol_res_spin import display_spin, generate_spin_string, return_spin, spin_loop
44 from pipe_control.minimise import assemble_scaling_matrix
45 from pipe_control.pipes import display
46 from specific_analyses.relax_disp.checks import check_missing_r1
47 from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff
48 from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, has_r1rho_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers
49 from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF
50 from specific_analyses.relax_disp.model import models_info, nesting_param
51 from specific_analyses.relax_disp.parameters import linear_constraints
52 from status import Status; status = Status()
53 from test_suite.system_tests.base_classes import SystemTestCase
54
55
56 if dep_check.C_module_exp_fn:
57 from specific_analyses.relax_fit.optimisation import func_wrapper, dfunc_wrapper, d2func_wrapper
58 from target_functions.relax_fit import jacobian, jacobian_chi2, setup
59
60 func = func_wrapper
61 dfunc = dfunc_wrapper
62 d2func = d2func_wrapper
63
64
66 """Class for testing various aspects specific to relaxation dispersion curve-fitting."""
67
68 - def __init__(self, methodName='runTest'):
69 """Skip certain tests if the C modules are non-functional.
70
71 @keyword methodName: The name of the test.
72 @type methodName: str
73 """
74
75
76 super(Relax_disp, self).__init__(methodName)
77
78
79 blacklist = [
80 'test_m61b_data_to_m61b'
81 ]
82 if methodName in blacklist:
83 status.skipped_tests.append([methodName, None, self._skip_type])
84
85
86 if not dep_check.C_module_exp_fn:
87
88 to_skip = [
89 "test_bug_atul_srivastava",
90 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp",
91 "test_bug_9999_slow_r1rho_r2eff_error_with_mc",
92 "test_estimate_r2eff_err",
93 "test_estimate_r2eff_err_auto",
94 "test_estimate_r2eff_err_methods",
95 "test_finite_value",
96 "test_exp_fit",
97 "test_m61_exp_data_to_m61",
98 "test_r1rho_kjaergaard_auto",
99 "test_r1rho_kjaergaard_auto_check_graphs",
100 "test_r1rho_kjaergaard_man",
101 "test_r1rho_kjaergaard_missing_r1",
102 "test_value_write_calc_rotating_frame_params_auto_analysis"
103 ]
104
105
106 if methodName in to_skip:
107 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
108
109
110 if not dep_check.scipy_module:
111
112 to_skip = [
113 "test_estimate_r2eff_err_methods"
114 ]
115
116
117 if methodName in to_skip:
118 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type])
119
120
121 if not dep_check.showApod_software:
122
123 to_skip = [
124 "test_show_apod_extract",
125 "test_show_apod_rmsd",
126 "test_show_apod_rmsd_to_file",
127 "test_show_apod_rmsd_dir_to_files"
128 ]
129
130
131 if methodName in to_skip:
132 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type])
133
134
135 if not dep_check.matplotlib_module:
136
137 to_skip = [
138 "test_repeat_cpmg"
139 ]
140
141
142 if methodName in to_skip:
143 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
144
145
147 """Set up for all the functional tests."""
148
149
150 self.interpreter.pipe.create('relax_disp', 'relax_disp')
151
152
153 ds.tmpdir = mkdtemp()
154 self.tmpdir = ds.tmpdir
155
156
158 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models.
159
160 @keyword folder: The name of the folder for the test data.
161 @type folder: str
162 @keyword model_analyse: The name of the model which will be tested.
163 @type model_analyse: str
164 """
165
166 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'
167
168
169 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder
170
171
172
173 sfrq_1 = 500.0*1E6
174 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
175 time_T2_1 = 0.05
176 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50]
177
178
179 r2eff_errs_1 = [0.0] * len(ncycs_1)
180 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1]
181
182 sfrq_2 = 600.0*1E6
183 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
184 time_T2_2 = 0.06
185 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60]
186
187
188 r2eff_errs_2 = [0.0] * len(ncycs_2)
189 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2]
190
191 sfrq_3 = 700.0*1E6
192 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3)
193 time_T2_3 = 0.07
194 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70]
195
196
197 r2eff_errs_3 = [0.0] * len(ncycs_3)
198 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3]
199
200
201 exps = [exp_1, exp_2, exp_3]
202
203 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3]
204 dw_arr = [1.0, 2.0, 3.0, 4.0]
205 pA_arr = [0.9]
206 kex_arr = [1000.]
207
208 spins = [
209 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}],
210 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}],
211 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}],
212 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}],
213 ]
214
215
216 pipe_name = 'base pipe'
217 pipe_type = 'relax_disp'
218 pipe_bundle = 'relax_disp'
219 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle)
220
221
222 for res_name, res_num, spin_name, params in spins:
223 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name)
224
225
226 self.interpreter.spin.isotope('15N', spin_id='@N')
227
228
229 exp_ids = []
230 for exp_i in exps:
231 sfrq, time_T2, ncycs, r2eff_errs = exp_i
232 exp_id = 'CPMG_%3.1f' % (sfrq/1E6)
233 exp_ids.append(exp_id)
234
235 ids = []
236 for ncyc in ncycs:
237 nu_cpmg = ncyc / time_T2
238 cur_id = '%s_%.1f' % (exp_id, nu_cpmg)
239 ids.append(cur_id)
240
241
242 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq)
243
244
245 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ)
246
247
248 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2)
249
250
251 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg)
252
253 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids)
254
255
256
257
258 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse)
259 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle)
260 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
261
262
263 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True):
264 exp_id = exp_ids[mi]
265 exp_i = exps[mi]
266 sfrq, time_T2, ncycs, r2eff_errs = exp_i
267
268
269 for res_name, res_num, spin_name, params in spins:
270 cur_spin_id = ":%i@%s"%(res_num, spin_name)
271
272
273 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_'))
274
275
276 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3)
277
278
279 self.interpreter.relax_disp.select_model(model=model_analyse)
280
281
282 self.interpreter.relax_disp.cluster('model_cluster', ":1-100")
283
284
285 low_arr = R20 + dw_arr + pA_arr + kex_arr
286 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1)
287
288
289 for i in range(len(spins)):
290 res_name, res_num, spin_name, params = spins[i]
291 cur_spin_id = ":%i@%s"%(res_num, spin_name)
292 cur_spin = return_spin(cur_spin_id)
293
294 for mo_param in cur_spin.params:
295 print(mo_param)
296
297 if isinstance(getattr(cur_spin, mo_param), dict):
298 for key, val in list(getattr(cur_spin, mo_param).items()):
299 should_be = params[mo_param][key]
300 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be)
301 self.assertAlmostEqual(val, should_be)
302 else:
303 should_be = float(params[mo_param])
304 val = getattr(cur_spin, mo_param)
305 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be)
306 self.assertAlmostEqual(val, should_be)
307
308
309
310 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
311
312
314 """Set up the data for the test_r1rho_kjaergaard_*() system tests."""
315
316
317 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
318
319
320 ds.pipe_name = 'base pipe'
321 ds.pipe_bundle = 'relax_disp'
322 ds.pipe_type = 'relax_disp'
323
324
325 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type)
326
327
328 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists')
329
330
331 self.interpreter.spin.isotope(isotope='15N')
332
333
334 NR_exp = 70
335
336
337 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r')
338 expfileslines = expfile.readlines()[:NR_exp]
339 expfile.close()
340
341
342 yOBS = 81.050
343
344 yCAR = 118.078
345 centerPPM_N15 = yCAR
346
347
348 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists')
349
350
351 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5}
352
353
354
355 j = 0
356 for i in range(len(expfileslines)):
357 line = expfileslines[i]
358 if line[0] == "#":
359 continue
360 else:
361
362 DIRN = line.split()[0]
363 I = int(line.split()[1])
364 deltadof2 = line.split()[2]
365 dpwr2slock = line.split()[3]
366 ncyc = int(line.split()[4])
367 trim = float(line.split()[5])
368 ss = int(line.split()[6])
369 set_sfrq = float(line.split()[7])
370 apod_rmsd = float(line.split()[8])
371 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock]
372
373
374 time_sl = 2*ncyc*trim
375
376
377 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc)
378 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc)
379
380
381 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height')
382
383
384 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id)
385
386
387 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho')
388
389
390 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength)
391
392
393 frq_N15_Hz = yOBS * 1E6
394 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6
395 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15
396
397
398 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm)
399
400
401 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl)
402
403
404 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz')
405
406
407 j += 1
408
409
410 print("Testing the number of settings")
411 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type)))
412 self.assertEqual(70, len(expfileslines))
413 self.assertEqual(69, j)
414 self.assertEqual(69, len(cdp.exp_type))
415
416
417 for curspin in cluster_ids:
418 print("Adding spin %s to cluster"%curspin)
419 self.interpreter.relax_disp.cluster('model_cluster', curspin)
420
421
422 for free_spin in cdp.clustering['free spins']:
423 print("Deselecting free spin %s"%free_spin)
424 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False)
425
426
427
428
429
430 ds.ref = dict()
431 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812]
432 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428]
433 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679]
434 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569]
435 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654]
436 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723]
437 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338]
438 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938]
439 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453]
440 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417]
441 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366]
442 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085]
443 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073]
444 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656]
445 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488]
446
447 ds.guess = dict()
448 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812]
449 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428]
450 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679]
451 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569]
452 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654]
453 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723]
454 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338]
455 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938]
456 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453]
457 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417]
458 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366]
459 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085]
460 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073]
461 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656]
462 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488]
463
464
465 for spin, spin_id in spin_loop(return_id=True):
466 if spin_id in cluster_ids:
467 print("spin_id %s in cluster ids"%(spin_id))
468 spin.kex = ds.guess[spin_id][6]
469 spin.phi_ex = ds.guess[spin_id][10]
470 else:
471 print("spin_id %s NOT in cluster ids"%(spin_id))
472
473 if read_R1:
474
475 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
476
477
510
511
539
540
542 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model.
543
544 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from:
545
546 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}).
547
548 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
549
550
551 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'.
552 @type data_list: list of str
553 """
554
555
556 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005'
557 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp')
558
559
560 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H')
561 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N')
562 self.interpreter.spin.element('H', spin_id='@H')
563 self.interpreter.spin.element('N', spin_id='@N')
564 self.interpreter.spin.isotope('1H', spin_id='@H')
565 self.interpreter.spin.isotope('15N', spin_id='@N')
566
567
568 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True)
569
570
571 data = [
572 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03],
573 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03],
574 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03],
575 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04],
576 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04],
577 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04],
578 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03],
579 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03],
580 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03],
581 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03],
582 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03],
583 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03],
584 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02],
585 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02],
586 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02],
587 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02],
588 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02],
589 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02]
590 ]
591 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0]
592 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0]
593 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0]
594 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0]
595 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0]
596 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0]
597
598
599 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data:
600
601 if data_type not in data_list:
602 continue
603
604
605 if data_type == 'SQ':
606 cpmg_frqs = cpmg_frqs_sq
607 elif data_type == '1H SQ':
608 cpmg_frqs = cpmg_frqs_1h_sq
609 elif data_type == 'DQ':
610 cpmg_frqs = cpmg_frqs_dq
611 elif data_type == 'ZQ':
612 cpmg_frqs = cpmg_frqs_zq
613 elif data_type == '1H MQ':
614 cpmg_frqs = cpmg_frqs_1h_mq
615 elif data_type == 'MQ':
616 cpmg_frqs = cpmg_frqs_mq
617
618
619 for cpmg_frq in cpmg_frqs:
620
621 new_id = "%s_%s" % (id, cpmg_frq)
622
623
624 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq)
625
626
627 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type)
628
629
630 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time)
631
632
633 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq)
634
635
636 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3)
637
638
639 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
640
641
642 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
643 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}.
644
645 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009
646 'SOD1-WT' CPMG data to the CR72 dispersion model.
647
648 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz.
649 Data is for experiment at 25 degree Celcius.
650 """
651
652
653 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25'
654
655
656 Exps = [
657 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ],
658 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ]
659
660
661 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type)
662
663
664 id_lists = []
665 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps:
666
667 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder)
668 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder)
669
670
671 id_list = list(key+str(i) for i in range(len(ncycs)))
672 id_lists.append(id_list)
673
674
675 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) )
676
677
678 for i in range(len(ncycs)):
679 ncyc = ncycs[i]
680 vcpmg = ncyc/time_T2
681
682
683 if float(vcpmg) == 0.0:
684 vcpmg = None
685 else:
686 vcpmg = round(float(vcpmg), 3)
687
688
689 current_id = id_list[i]
690
691
692 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG')
693
694
695 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz')
696
697
698 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2)
699
700
701 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg)
702
703
704 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5])
705 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5])
706
707
708 self.interpreter.spectrum.error_analysis(subset=id_lists[0])
709 self.interpreter.spectrum.error_analysis(subset=id_lists[1])
710
711
712 self.interpreter.spin.isotope(isotope='15N')
713
714
715
716
717 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H",
718 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H",
719 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H",
720 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H",
721 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H",
722 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"]
723
724
725 self.assertEqual(64, len(glob_assn ))
726
727
728
729 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)")
730
731
732 relax_glob_ids = []
733
734
735 for assn in glob_assn:
736
737 m = r.match(assn)
738
739 relax_string = ":%s@%s"%(m.group(2), m.group(3))
740
741
742 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string])
743
744
745
746
747 self.interpreter.deselect.all()
748
749
750 for i in select_spin_index:
751 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False)
752
753
754
755
756 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff)
757 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff)
758
759
760 MODEL = "R2eff"
761 self.interpreter.relax_disp.select_model(model=MODEL)
762
763 self.interpreter.minimise.calculate(verbosity=1)
764
765
767 """Function for setting up a few spins for the given pipe."""
768
769
770 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
771
772
773 file = open(data_path+sep+'R1_fitted_values.txt')
774 lines = file.readlines()
775 file.close()
776
777 for i, line in enumerate(lines):
778
779 line_split = line.split()
780
781 if line_split[0] == "#":
782 continue
783
784 mol_name = line_split[0]
785 mol_name = None
786 res_num = int(line_split[1])
787 res_name = line_split[2]
788 spin_num = line_split[3]
789 spin_num = None
790 spin_name = line_split[4]
791
792
793 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
794
795
797 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data."""
798
799
800 self.interpreter.reset()
801
802
803 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'
804 self.interpreter.state.load(data_path+sep+'r2eff_values')
805
806
807 model = 'NS R1rho 2-site'
808 pipe_name = "%s - relax_disp" % model
809 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp')
810 self.interpreter.pipe.switch(pipe_name=pipe_name)
811
812
813 self.interpreter.relax_disp.select_model(model=model)
814
815
816 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
817
818
819 spin1 = cdp.mol[0].res[0].spin[0]
820 spin2 = cdp.mol[0].res[1].spin[0]
821
822
823 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
824 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
825
826
827 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684}
828 spin1.pA = 0.779782428085762
829 spin1.dw = 7.57855284496424
830 spin1.kex = 1116.7911285203
831 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337}
832 spin2.pA = 0.826666229688602
833 spin2.dw = 9.5732624231366
834 spin2.kex = 1380.46162655657
835
836
837 if clustering:
838 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100")
839
840
841 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
842
843
844 print("\n\nOptimised parameters:\n")
845 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
846 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
847 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
848 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA))
849 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw))
850 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex))
851 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
852
853
855 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed.
856
857 Support requst sr #3154 U{https://gna.org/support/index.php?3154}.
858
859 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s.
860 """
861
862
863 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014'
864
865
866 pipe_name = 'base pipe'
867 pipe_type = 'relax_disp'
868 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
869
870
871 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type)
872
873
874 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H')
875
876
877 self.interpreter.spin.isotope('1H', spin_id='@H')
878
879
880
881 ncycs = [2, 4, 8, 10, 20, 40, 500]
882 ids = []
883 for ncyc in ncycs:
884 ids.append('CPMG_%s' % ncyc)
885
886 print("\n\nThe experiment IDs are %s." % ids)
887
888
889
890 sfrq = 200. * 1E6
891
892
893 Trelax = 0.04
894
895
896 for i in range(len(ids)):
897 id = ids[i]
898
899 self.interpreter.spectrometer.frequency(id=id, frq=sfrq)
900
901
902 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
903
904
905 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax)
906
907
908 ncyc = ncycs[i]
909 nu_cpmg = ncyc / Trelax
910 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg)
911
912
913 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff)
914 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff)
915
916
917 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3)
918
919
920 data = [
921 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}],
922 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ],
923 ['dispersion_points', len(ncycs)],
924 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}],
925 ['exp_type_list', ['SQ CPMG']],
926 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}],
927 ['spectrometer_frq_count', 1],
928 ['spectrometer_frq_list', [sfrq]],
929 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']]
930 ]
931 for name, value in data:
932
933 self.assert_(hasattr(cdp, name))
934
935
936 obj = getattr(cdp, name)
937 if not isinstance(data, dict):
938 self.assertEqual(obj, value)
939
940
941 else:
942 for id in ids:
943 self.assertEqual(obj[id], value[id])
944
945
946 n_data = [
947 [ 50.000000, 10.367900, 0.1],
948 [ 100.000000, 10.146849, 0.1],
949 [ 200.000000, 9.765987, 0.1],
950 [ 250.000000, 9.409789, 0.1],
951 [ 500.000000, 5.829819, 0.1],
952 [ 1000.000000, 3.191928, 0.1],
953 [ 12500.000000, 2.008231, 0.1]
954 ]
955 for disp_point, value, error in n_data:
956 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point
957 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value)
958 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error)
959
960
961 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq)
962
963
964 MODEL = "B14"
965
966
967 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
968 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
969 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
970
971
972 self.interpreter.relax_disp.select_model(model=MODEL)
973
974
975 grid_results = []
976 mini_results = []
977
978
979
980
981 GRID = 13
982
983 if GRID:
984
985
986 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
987
988
989 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1)
990
991
992 else:
993 for param in MODEL_PARAMS[MODEL]:
994 self.interpreter.value.set(param=param, index=None)
995
996 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1)
997
998
999 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1000 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1001
1002
1003
1004 set_func_tol = 1e-10
1005 set_max_iter = 1000
1006 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
1007
1008
1009 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1010 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1011
1012
1013 for i in range(len(grid_results)):
1014 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
1015 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
1016 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn))
1017 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn))
1018
1019
1020
1021 kex = 1000.
1022
1023 pb = 0.01
1024
1025 dw_ppm = 2.
1026
1027 R2g = 2.
1028
1029 R2e = 2.
1030
1031
1032
1033 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6)
1034
1035 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6)
1036 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8)
1037 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1038
1039
1041 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}.
1042
1043 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}.
1044 """
1045
1046
1047 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014'
1048
1049
1050 pipe_name = 'base pipe'
1051 pipe_type = 'relax_disp'
1052 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
1053
1054
1055 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type)
1056
1057
1058
1059 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H')
1060
1061
1062 self.interpreter.spin.isotope('1H', spin_id='@H')
1063
1064
1065
1066 ncycs = [2, 4, 8, 10, 20, 40, 500]
1067 ids = []
1068 for ncyc in ncycs:
1069 ids.append('CPMG_%s' % ncyc)
1070
1071 print("\n\nThe experiment IDs are %s." % ids)
1072
1073
1074
1075 sfrq = 200. * 1E6
1076
1077
1078 Trelax = 0.04
1079
1080
1081 for i in range(len(ids)):
1082 id = ids[i]
1083
1084 self.interpreter.spectrometer.frequency(id=id, frq=sfrq)
1085
1086
1087 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
1088
1089
1090 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax)
1091
1092
1093 ncyc = ncycs[i]
1094 nu_cpmg = ncyc / Trelax
1095 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg)
1096
1097
1098 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff)
1099 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff)
1100
1101
1102 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3)
1103
1104
1105 data = [
1106 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}],
1107 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ],
1108 ['dispersion_points', len(ncycs)],
1109 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}],
1110 ['exp_type_list', ['SQ CPMG']],
1111 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}],
1112 ['spectrometer_frq_count', 1],
1113 ['spectrometer_frq_list', [sfrq]],
1114 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']]
1115 ]
1116 for name, value in data:
1117
1118 self.assert_(hasattr(cdp, name))
1119
1120
1121 obj = getattr(cdp, name)
1122 if not isinstance(data, dict):
1123 self.assertEqual(obj, value)
1124
1125
1126 else:
1127 for id in ids:
1128 self.assertEqual(obj[id], value[id])
1129
1130
1131 n_data = [
1132 [ 50.000000, 10.286255, 0.1],
1133 [ 100.000000, 10.073083, 0.1],
1134 [ 200.000000, 9.692746, 0.1],
1135 [ 250.000000, 9.382441, 0.1],
1136 [ 500.000000, 6.312396, 0.1],
1137 [ 1000.000000, 3.957029, 0.1],
1138 [ 12500.000000, 2.880420, 0.1]
1139 ]
1140 for disp_point, value, error in n_data:
1141 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point
1142 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value)
1143 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error)
1144
1145
1146 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq)
1147
1148
1149 MODEL = "B14 full"
1150
1151
1152 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
1153 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
1154 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
1155
1156
1157 self.interpreter.relax_disp.select_model(model=MODEL)
1158
1159
1160 grid_results = []
1161 mini_results = []
1162 clust_results = []
1163
1164
1165
1166
1167 GRID = 13
1168
1169 if GRID:
1170
1171
1172 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
1173
1174
1175 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1)
1176
1177
1178 else:
1179 for param in MODEL_PARAMS[MODEL]:
1180 self.interpreter.value.set(param=param, index=None)
1181
1182 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1)
1183
1184
1185 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1186 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1187
1188
1189
1190 set_func_tol = 1e-11
1191 set_max_iter = 10000
1192 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
1193
1194
1195 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1196 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1197
1198 print("\n# Now print before and after minimisation-\n")
1199
1200
1201 for i in range(len(grid_results)):
1202 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
1203 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
1204 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn))
1205 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn))
1206
1207
1208
1209 kex = 1000.
1210
1211 pb = 0.01
1212
1213 dw_ppm = 2.
1214
1215 R2g = 2.
1216
1217 R2e = 100.
1218
1219
1220
1221 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3)
1222 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3)
1223
1224 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6)
1225 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6)
1226 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1227
1228
1230 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB.
1231 This uses CPMG data from:
1232 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE.
1233 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations.
1234 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886
1235 """
1236
1237
1238 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011'
1239
1240
1241 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins')
1242
1243
1244 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False)
1245
1246
1247 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True)
1248 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False)
1249
1250 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1251 print(spin_id)
1252 if resn == 'C':
1253 print(resi, resn)
1254
1255
1256
1257 self.interpreter.bmrb.thiol_state(state='not reported')
1258
1259
1260
1261
1262 self.interpreter.bmrb.display()
1263
1264
1266 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected."""
1267
1268
1269 self.interpreter.reset()
1270
1271
1272 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2'
1273 self.interpreter.state.load(state, force=True)
1274
1275
1276 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1277
1278
1280 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data."""
1281
1282
1283 self.interpreter.reset()
1284
1285
1286 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2'
1287 self.interpreter.state.load(state, force=True)
1288
1289
1290 relax_disp.Relax_disp.opt_func_tol = 1e-5
1291 relax_disp.Relax_disp.opt_max_iterations = 1000
1292 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1293
1294
1296 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis."""
1297
1298
1299 self.interpreter.reset()
1300
1301
1302 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
1303 self.interpreter.state.load(state, force=True)
1304
1305
1306 relax_disp.Relax_disp.opt_func_tol = 1e-5
1307 relax_disp.Relax_disp.opt_max_iterations = 1000
1308 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1309
1310
1312 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate()."""
1313
1314
1315 self.interpreter.reset()
1316
1317
1318 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2'
1319 self.interpreter.state.load(state, force=True)
1320
1321
1322 self.interpreter.minimise.calculate(verbosity=1)
1323
1324
1326 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis."""
1327
1328
1329 self.interpreter.reset()
1330
1331
1332 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2'
1333 self.interpreter.state.load(state, force=True)
1334
1335
1336 relax_disp.Relax_disp.opt_func_tol = 1e-5
1337 relax_disp.Relax_disp.opt_max_iterations = 1000
1338 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1339
1340
1342 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError."""
1343
1344
1345 self.interpreter.reset()
1346
1347
1348 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2'
1349 self.interpreter.state.load(state, force=True)
1350
1351
1352 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered'
1353 relax_disp.Relax_disp.opt_func_tol = 1e-5
1354 relax_disp.Relax_disp.opt_max_iterations = 1000
1355 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=2, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1356
1357
1363
1364
1370
1371
1377
1378
1384
1385
1387 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis."""
1388
1389
1390 self.interpreter.reset()
1391
1392
1393 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2'
1394 self.interpreter.state.load(state, force=True)
1395
1396 param = 'k_AB'
1397
1398 for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
1399 print(spin_id, spin.params)
1400 if param in spin.params:
1401 print(spin_id, spin.k_AB, spin.k_AB_err)
1402
1403
1404 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True)
1405
1406
1407
1408 param = 'r2'
1409 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True)
1410
1411 file = open(self.tmpdir+sep+'%s.out'%param)
1412 lines = file.readlines()
1413 file.close()
1414
1415 for i, line in enumerate(lines):
1416
1417 line_split = line.split()
1418 print(line_split)
1419
1420 if len(line_split) > 1:
1421
1422 if line_split[0] == "#" and line_split[1] == 'mol_name':
1423 nr_split_header = len(line_split)
1424 nr_split_header_i = i
1425 break
1426
1427
1428 line_split_val = lines[nr_split_header_i + 1].split()
1429 print(line_split_val)
1430
1431
1432 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1433
1434
1435 param = 'r2eff'
1436 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True)
1437
1438 file = open(self.tmpdir+sep+'%s.out'%param)
1439 lines = file.readlines()
1440 file.close()
1441
1442 for i, line in enumerate(lines):
1443
1444 line_split = line.split()
1445 print(line_split)
1446
1447 if len(line_split) > 1:
1448
1449 if line_split[0] == "#" and line_split[1] == 'mol_name':
1450 nr_split_header = len(line_split)
1451 nr_split_header_i = i
1452 break
1453
1454
1455 line_split_val = lines[nr_split_header_i + 1].split()
1456 print(line_split_val)
1457
1458
1459 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1460
1461
1463 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations."""
1464
1465
1466 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff"
1467
1468
1469 self.interpreter.results.read(prev_data_path + sep + 'results')
1470
1471
1472 graph_nr = 1
1473 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False):
1474 print("\nGraph nr %i" % graph_nr)
1475 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point):
1476 print(exp_type, frq, offset, point, time)
1477 graph_nr += 1
1478
1479
1480
1481
1482 precalc = True
1483 for spin in spin_loop(skip_desel=True):
1484
1485 if not hasattr(spin, 'peak_intensity_err'):
1486 precalc = False
1487 break
1488
1489
1490 for id in cdp.spectrum_ids:
1491 if id not in spin.peak_intensity_err:
1492 precalc = False
1493 break
1494
1495
1496 if precalc:
1497 print("Skipping the error analysis as it has already been performed.")
1498
1499 else:
1500
1501 for frq in loop_frq():
1502
1503 ids = []
1504 for id in cdp.spectrum_ids:
1505
1506 match_frq = True
1507 if frq != None and cdp.spectrometer_frq[id] != frq:
1508 match_frq = False
1509
1510
1511 if match_frq:
1512 ids.append(id)
1513
1514
1515 self.interpreter.spectrum.error_analysis(subset=ids)
1516
1517 print("has_exponential_exp_type:", has_exponential_exp_type())
1518
1519 model = 'R2eff'
1520 self.interpreter.relax_disp.select_model(model)
1521
1522 for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
1523
1524
1525
1526
1527 setattr(spin, 'r2eff', {})
1528 setattr(spin, 'r2eff_err', {})
1529 setattr(spin, 'i0', {})
1530 setattr(spin, 'i0_err', {})
1531
1532
1533 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1)
1534
1535
1536 my_dic = {}
1537
1538
1539 NE = 0
1540 NS = 1
1541 NM = 0
1542 NO = 0
1543 ND = 0
1544 NT = 0
1545
1546 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
1547
1548 if ei > NE:
1549 NE = ei
1550 if mi > NM:
1551 NM = mi
1552 if oi > NO:
1553 NO = oi
1554 if di > ND:
1555 ND = di
1556
1557 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True):
1558
1559 if ti > NT:
1560 NT = ti
1561
1562
1563 NE = NE + 1
1564 NM = NM + 1
1565 NO = NO + 1
1566 ND = ND + 1
1567 NT = NT + 1
1568
1569
1570 values_arr = zeros([NE, NS, NM, NO, ND, NT])
1571 errors_arr = zeros([NE, NS, NM, NO, ND, NT])
1572 times_arr = zeros([NE, NS, NM, NO, ND, NT])
1573 struct_arr = zeros([NE, NS, NM, NO, ND, NT])
1574 param_key_list = []
1575
1576
1577
1578 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1579
1580 my_dic[spin_id] = {}
1581
1582
1583 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
1584
1585
1586
1587
1588 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
1589
1590 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
1591
1592
1593 param_key_list.append(param_key)
1594
1595
1596 my_dic[spin_id][param_key] = {}
1597
1598
1599 R2eff_value = getattr(cur_spin, 'r2eff')[param_key]
1600 i0_value = getattr(cur_spin, 'i0')[param_key]
1601
1602
1603 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value
1604 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value
1605
1606
1607
1608 values = []
1609 errors = []
1610 times = []
1611 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True):
1612 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None)
1613 values.append(value)
1614
1615 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)
1616 errors.append(error)
1617 times.append(time)
1618
1619
1620 values_arr[ei, 0, mi, oi, di, ti] = value
1621 errors_arr[ei, 0, mi, oi, di, ti] = error
1622 times_arr[ei, 0, mi, oi, di, ti] = time
1623 struct_arr[ei, 0, mi, oi, di, ti] = 1.0
1624
1625
1626
1627
1628 w = log(array(values))
1629 x = - array(times)
1630 n = len(times)
1631
1632 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 )
1633 a = 1./n * sum(w) - b * 1./n * sum(x)
1634 R2eff_est = b
1635 i0_est = exp(a)
1636
1637 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est
1638 my_dic[spin_id][param_key]['i0_est'] = i0_est
1639
1640
1641
1642
1643
1644
1645
1646 set_func_tol = 1e-25
1647 set_max_iter = int(1e7)
1648 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
1649
1650
1651 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1652
1653 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
1654
1655
1656 print("Optimised parameters for spin: %s" % (spin_string))
1657
1658 for exp_type, frq, offset, point in loop_exp_frq_offset_point():
1659
1660 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
1661
1662
1663 R2eff_value = getattr(cur_spin, 'r2eff')[param_key]
1664 i0_value = getattr(cur_spin, 'i0')[param_key]
1665
1666
1667 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid']
1668 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid']
1669 R2eff_est = my_dic[spin_id][param_key]['R2eff_est']
1670 i0_est = my_dic[spin_id][param_key]['i0_est']
1671
1672
1673
1674
1675
1676 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est))
1677 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est))
1678
1679 print(NE, NS, NM, NO, ND, NT)
1680 for param_key in param_key_list:
1681 print(" '%s'," % param_key)
1682 print(values_arr.shape)
1683
1684
1685 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1686
1687
1688
1689
1690
1691
1693 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data
1694 shows it is exponential fitting, but only one time point is added per file.
1695
1696 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}:
1697 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}:
1698 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}:
1699
1700 """
1701
1702
1703 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava'
1704 file = data_path + sep + 'bug_script.py'
1705
1706
1707 self.interpreter.script(file=file, dir=None)
1708
1709
1710 GRID_INC = 11
1711
1712
1713
1714
1715
1716 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1717 print(mol_name, resi, resn, spin_id)
1718
1719
1720 for id in cdp.exp_type:
1721 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id])
1722
1723
1724
1725
1726 if True:
1727
1728 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
1729
1730
1731 check_intensity_errors()
1732
1733
1734 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type():
1735 self.interpreter.minimise.calculate()
1736
1737
1738 else:
1739 constraints = False
1740 min_algor = 'Newton'
1741 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC)
1742 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints)
1743
1744
1745 if False:
1746
1747 par_attr_list = ['r2eff', 'i0']
1748
1749
1750 my_dic = {}
1751 param_key_list = []
1752 est_keys = []
1753 est_key = 'grid'
1754 est_keys.append(est_key)
1755 spin_id_list = []
1756
1757 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1758
1759 my_dic[spin_id] = {}
1760
1761
1762 my_dic[spin_id][est_key] = {}
1763
1764
1765 spin_id_list.append(spin_id)
1766
1767
1768 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
1769
1770 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
1771
1772 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
1773
1774
1775
1776 param_key_list.append(param_key)
1777
1778
1779 my_dic[spin_id][est_key][param_key] = {}
1780
1781
1782
1783 for par_attr in par_attr_list:
1784 if hasattr(cur_spin, par_attr):
1785 get_par_attr = getattr(cur_spin, par_attr)[param_key]
1786 else:
1787 get_par_attr = 0.0
1788
1789
1790 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr
1791
1792
1793 values = []
1794 errors = []
1795 times = []
1796 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True):
1797 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None)
1798 values.append(value)
1799
1800 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)
1801 errors.append(error)
1802 times.append(time)
1803
1804
1805 my_dic[spin_id][est_key][param_key]['values'] = values
1806 my_dic[spin_id][est_key][param_key]['errors'] = errors
1807 my_dic[spin_id][est_key][param_key]['times'] = times
1808
1809
1810
1811
1812
1813 MODELS = ['R2eff', 'No Rex']
1814
1815
1816 MC_NUM = 10
1817
1818
1819 MC_SIM_ALL_MODELS = False
1820
1821
1822 RESULTS_DIR = ds.tmpdir
1823
1824
1825 PRE_RUN_DIR = None
1826
1827
1828 MODSEL = 'AIC'
1829
1830
1831 NUMERIC_ONLY = False
1832
1833
1834 INSIGNIFICANCE = 1.0
1835
1836
1837 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1838
1839
1841 """Test data, where peak intensities are negative in CPMG
1842
1843 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride).
1844 """
1845
1846 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223'
1847
1848
1849 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path)
1850
1851
1852 self.interpreter.spin.isotope(isotope='15N')
1853
1854
1855 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height')
1856
1857
1858 ncycfile=open(data_path + sep + 'ncyc.txt', 'r')
1859
1860
1861 ncyclist = []
1862
1863 i = 0
1864 for line in ncycfile:
1865 ncyc = line.split()[0]
1866 time_T2 = float(line.split()[1])
1867 vcpmg = line.split()[2]
1868 set_sfrq = float(line.split()[3])
1869 rmsd_err = float(line.split()[4])
1870
1871
1872 if float(vcpmg) == 0.0:
1873 vcpmg = None
1874 else:
1875 vcpmg = round(float(vcpmg), 3)
1876
1877
1878 ncyclist.append(int(ncyc))
1879
1880
1881 current_id = "Z_A%s"%(i)
1882
1883
1884 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG')
1885
1886
1887 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id)
1888
1889
1890 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz')
1891
1892
1893 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2)
1894
1895
1896 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg)
1897
1898 i += 1
1899
1900
1901 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15'])
1902
1903
1904
1905
1906 MODELS = [MODEL_R2EFF, MODEL_NOREX]
1907 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC'
1908
1909 results_dir = ds.tmpdir
1910
1911
1912 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL)
1913
1914
1915 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
1916
1917 if spin_id == ':4@N':
1918 self.assertEqual(len(cur_spin.r2eff), 14)
1919 else:
1920 self.assertEqual(len(cur_spin.r2eff), 15)
1921
1922
1924 """Test of the check_missing_r1() function."""
1925
1926
1927 self.setup_missing_r1_spins()
1928
1929
1930 exp_type = 'R1rho'
1931 frq = 800.1 * 1E6
1932
1933 spectrum_id='test'
1934
1935
1936 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type)
1937
1938
1939 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz')
1940
1941
1942 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94)
1943 self.assertEqual(check_missing_r1_return, True)
1944
1945
1946 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF)
1947 self.assertEqual(check_missing_r1_return, False)
1948
1949
1950 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
1951
1952
1953 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
1954
1955
1956 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94)
1957 self.assertEqual(check_missing_r1_return, False)
1958
1959
1961 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis.
1962
1963 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis.
1964
1965 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
1966 """
1967
1968
1969
1970
1971
1972 model_create = 'B14'
1973
1974 model_analyse = 'NS CPMG 2-site 3D'
1975
1976
1977 sfrq_1 = 599.8908617*1E6
1978 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
1979 time_T2_1 = 0.06
1980 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
1981
1982 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
1983 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1]
1984
1985 sfrq_2 = 499.8908617*1E6
1986 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
1987 time_T2_2 = 0.05
1988 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
1989
1990 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
1991 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2]
1992
1993
1994 exps = [exp_1, exp_2]
1995
1996 spins = [
1997 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ],
1998 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ]
1999 ]
2000
2001
2002 ds.data = [model_create, model_analyse, spins, exps]
2003
2004
2005 ds.tmpdir = ds.tmpdir
2006
2007
2008
2009 ds.resdir = ds.tmpdir
2010
2011
2012 ds.r20_from_min_r2eff = True
2013
2014
2015 ds.insignificance = 0.0
2016
2017
2018 ds.GRID_INC = None
2019
2020
2021 ds.do_cluster = True
2022
2023
2024
2025 ds.set_func_tol = 1e-1
2026
2027
2028
2029 ds.set_max_iter = 1000
2030
2031
2032 ds.verbosity = 1
2033
2034
2035 ds.rel_change = 0.05
2036
2037
2038 ds.plot_curves = False
2039
2040
2041 ds.sherekhan_input = False
2042
2043
2044 ds.opendx = False
2045
2046
2047 ds.r2eff_err = 0.1
2048
2049
2050 ds.print_res = True
2051
2052
2053 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2054
2055 cur_spins = ds.data[2]
2056
2057 for i in range(len(cur_spins)):
2058 res_name, res_num, spin_name, params = cur_spins[i]
2059 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2060 cur_spin = return_spin(cur_spin_id)
2061
2062 grid_params = ds.grid_results[i][3]
2063
2064
2065 min_params = ds.clust_results[i][3]
2066
2067 print("For spin: '%s'"%cur_spin_id)
2068 for mo_param in cur_spin.params:
2069
2070 if isinstance(getattr(cur_spin, mo_param), dict):
2071 grid_r2 = grid_params[mo_param]
2072 min_r2 = min_params[mo_param]
2073 set_r2 = params[mo_param]
2074 for key, val in list(set_r2.items()):
2075 grid_r2_frq = grid_r2[key]
2076 min_r2_frq = min_r2[key]
2077 set_r2_frq = set_r2[key]
2078 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2079 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2080 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) )
2081 if rel_change > ds.rel_change:
2082 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2083 print("###################################")
2084
2085
2086 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1)
2087 else:
2088 grid_val = grid_params[mo_param]
2089 min_val = min_params[mo_param]
2090 set_val = params[mo_param]
2091 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2092 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) )
2093 if rel_change > ds.rel_change:
2094 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2095 print("###################################")
2096
2097
2098 if mo_param == 'dw':
2099 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2100 elif mo_param == 'kex':
2101 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2102 elif mo_param == 'pA':
2103 self.assertAlmostEqual(set_val, min_val, 2)
2104
2105
2107 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis.
2108
2109 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis.
2110
2111 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
2112 """
2113
2114
2115
2116
2117
2118 model_create = 'B14'
2119
2120 model_analyse = 'NS CPMG 2-site star'
2121
2122
2123 sfrq_1 = 599.8908617*1E6
2124 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2125 time_T2_1 = 0.06
2126 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2127
2128 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
2129 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1]
2130
2131 sfrq_2 = 499.8908617*1E6
2132 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2133 time_T2_2 = 0.05
2134 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2135
2136 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
2137 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2]
2138
2139
2140 exps = [exp_1, exp_2]
2141
2142 spins = [
2143 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ],
2144 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ]
2145 ]
2146
2147
2148 ds.data = [model_create, model_analyse, spins, exps]
2149
2150
2151 ds.tmpdir = ds.tmpdir
2152
2153
2154
2155 ds.resdir = ds.tmpdir
2156
2157
2158 ds.r20_from_min_r2eff = True
2159
2160
2161 ds.insignificance = 0.0
2162
2163
2164 ds.GRID_INC = None
2165
2166
2167 ds.do_cluster = True
2168
2169
2170
2171 ds.set_func_tol = 1e-1
2172
2173
2174
2175 ds.set_max_iter = 1000
2176
2177
2178 ds.verbosity = 1
2179
2180
2181 ds.rel_change = 0.05
2182
2183
2184 ds.plot_curves = False
2185
2186
2187 ds.sherekhan_input = False
2188
2189
2190 ds.opendx = False
2191
2192
2193 ds.r2eff_err = 0.1
2194
2195
2196 ds.print_res = True
2197
2198
2199 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2200
2201 cur_spins = ds.data[2]
2202
2203 for i in range(len(cur_spins)):
2204 res_name, res_num, spin_name, params = cur_spins[i]
2205 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2206 cur_spin = return_spin(cur_spin_id)
2207
2208 grid_params = ds.grid_results[i][3]
2209
2210
2211 min_params = ds.clust_results[i][3]
2212
2213 print("For spin: '%s'"%cur_spin_id)
2214 for mo_param in cur_spin.params:
2215
2216 if isinstance(getattr(cur_spin, mo_param), dict):
2217 grid_r2 = grid_params[mo_param]
2218 min_r2 = min_params[mo_param]
2219 set_r2 = params[mo_param]
2220 for key, val in list(set_r2.items()):
2221 grid_r2_frq = grid_r2[key]
2222 min_r2_frq = min_r2[key]
2223 set_r2_frq = set_r2[key]
2224 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2225 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2226 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) )
2227 if rel_change > ds.rel_change:
2228 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2229 print("###################################")
2230
2231
2232 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1)
2233 else:
2234 grid_val = grid_params[mo_param]
2235 min_val = min_params[mo_param]
2236 set_val = params[mo_param]
2237 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2238 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) )
2239 if rel_change > ds.rel_change:
2240 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2241 print("###################################")
2242
2243
2244 if mo_param == 'dw':
2245 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2246 elif mo_param == 'kex':
2247 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2248 elif mo_param == 'pA':
2249 self.assertAlmostEqual(set_val, min_val, 2)
2250
2251
2253 """Test synthetic cpmg data.
2254
2255 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72.
2256 """
2257
2258
2259
2260
2261
2262 model_create = 'NS CPMG 2-site 3D'
2263
2264 model_analyse = 'CR72'
2265
2266 sfrq_1 = 599.8908617*1E6
2267 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2268 time_T2_1 = 0.06
2269 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2270 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0]
2271 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1]
2272
2273 sfrq_2 = 499.8908617*1E6
2274 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2275 time_T2_2 = 0.05
2276 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2277 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0]
2278 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2]
2279
2280
2281 exps = [exp_1, exp_2]
2282
2283 spins = [
2284 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ]
2285 ]
2286
2287
2288 ds.data = [model_create, model_analyse, spins, exps]
2289
2290
2291 ds.tmpdir = ds.tmpdir
2292
2293
2294
2295 ds.resdir = ds.tmpdir
2296
2297
2298 ds.r20_from_min_r2eff = True
2299
2300
2301 ds.insignificance = 0.0
2302
2303
2304 ds.GRID_INC = 8
2305
2306
2307 ds.do_cluster = False
2308
2309
2310
2311 ds.set_func_tol = 1e-9
2312
2313
2314
2315 ds.set_max_iter = 1000
2316
2317
2318 ds.verbosity = 1
2319
2320
2321 ds.rel_change = 0.05
2322
2323
2324 ds.plot_curves = False
2325
2326
2327 ds.sherekhan_input = False
2328
2329
2330 ds.opendx = False
2331
2332
2333 ds.r2eff_err = 0.1
2334
2335
2336 ds.print_res = False
2337
2338
2339 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2340
2341 cur_spins = ds.data[2]
2342
2343 for i in range(len(cur_spins)):
2344 res_name, res_num, spin_name, params = cur_spins[i]
2345 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2346 cur_spin = return_spin(cur_spin_id)
2347
2348 grid_params = ds.grid_results[i][3]
2349 min_params = ds.min_results[i][3]
2350
2351 print("For spin: '%s'"%cur_spin_id)
2352 for mo_param in cur_spin.params:
2353
2354 if isinstance(getattr(cur_spin, mo_param), dict):
2355 grid_r2 = grid_params[mo_param]
2356 min_r2 = min_params[mo_param]
2357 set_r2 = params[mo_param]
2358 for key, val in list(set_r2.items()):
2359 grid_r2_frq = grid_r2[key]
2360 min_r2_frq = min_r2[key]
2361 set_r2_frq = set_r2[key]
2362 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2363 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2364 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) )
2365 if rel_change > ds.rel_change:
2366 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2367 print("###################################")
2368
2369
2370 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2)
2371 else:
2372 grid_val = grid_params[mo_param]
2373 min_val = min_params[mo_param]
2374 set_val = params[mo_param]
2375 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2376 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) )
2377 if rel_change > ds.rel_change:
2378 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2379 print("###################################")
2380
2381
2382 if mo_param == 'dw':
2383 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2384 elif mo_param == 'kex':
2385 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2386 elif mo_param == 'pA':
2387 self.assertAlmostEqual(set_val, min_val, 3)
2388
2389
2391 """Test synthetic cpmg data.
2392
2393 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14.
2394 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data.
2395 """
2396
2397
2398
2399
2400
2401 model_create = 'NS CPMG 2-site 3D'
2402
2403 model_analyse = 'B14'
2404
2405 sfrq_1 = 599.8908617*1E6
2406 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2407 time_T2_1 = 0.06
2408 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2409 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0]
2410 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1]
2411
2412 sfrq_2 = 499.8908617*1E6
2413 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2414 time_T2_2 = 0.05
2415 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2416 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0]
2417 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2]
2418
2419
2420 exps = [exp_1, exp_2]
2421
2422 spins = [
2423 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ]
2424 ]
2425
2426
2427 ds.data = [model_create, model_analyse, spins, exps]
2428
2429
2430 ds.tmpdir = ds.tmpdir
2431
2432
2433
2434 ds.resdir = ds.tmpdir
2435
2436
2437 ds.r20_from_min_r2eff = True
2438
2439
2440 ds.insignificance = 0.0
2441
2442
2443 ds.GRID_INC = 8
2444
2445
2446 ds.do_cluster = False
2447
2448
2449
2450 ds.set_func_tol = 1e-9
2451
2452
2453
2454 ds.set_max_iter = 1000
2455
2456
2457 ds.verbosity = 1
2458
2459
2460 ds.rel_change = 0.05
2461
2462
2463 ds.plot_curves = False
2464
2465
2466 ds.sherekhan_input = False
2467
2468
2469 ds.opendx = False
2470
2471
2472 ds.r2eff_err = 0.1
2473
2474
2475 ds.print_res = False
2476
2477
2478 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2479
2480 cur_spins = ds.data[2]
2481
2482 for i in range(len(cur_spins)):
2483 res_name, res_num, spin_name, params = cur_spins[i]
2484 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2485 cur_spin = return_spin(cur_spin_id)
2486
2487 grid_params = ds.grid_results[i][3]
2488 min_params = ds.min_results[i][3]
2489
2490 print("For spin: '%s'"%cur_spin_id)
2491 for mo_param in cur_spin.params:
2492
2493 if isinstance(getattr(cur_spin, mo_param), dict):
2494 grid_r2 = grid_params[mo_param]
2495 min_r2 = min_params[mo_param]
2496 set_r2 = params[mo_param]
2497 for key, val in list(set_r2.items()):
2498 grid_r2_frq = grid_r2[key]
2499 min_r2_frq = min_r2[key]
2500 set_r2_frq = set_r2[key]
2501 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2502 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2503 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) )
2504 if rel_change > ds.rel_change:
2505 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2506 print("###################################")
2507
2508
2509 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2)
2510 else:
2511 grid_val = grid_params[mo_param]
2512 min_val = min_params[mo_param]
2513 set_val = params[mo_param]
2514 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2515 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) )
2516 if rel_change > ds.rel_change:
2517 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2518 print("###################################")
2519
2520
2521 if mo_param == 'dw':
2522 self.assertAlmostEqual(set_val/10, min_val/10, 5)
2523 elif mo_param == 'kex':
2524 self.assertAlmostEqual(set_val/1000, min_val/1000, 5)
2525 elif mo_param == 'pA':
2526 self.assertAlmostEqual(set_val, min_val, 6)
2527
2528
2530 """Test synthetic cpmg data. For CR72 with small noise and cluster.
2531
2532 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
2533 """
2534
2535
2536
2537
2538
2539 model_create = 'NS CPMG 2-site 3D'
2540
2541 model_analyse = 'CR72'
2542
2543
2544 sfrq_1 = 599.8908617*1E6
2545 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2546 time_T2_1 = 0.06
2547 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2548 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05]
2549
2550 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1]
2551
2552 sfrq_2 = 499.8908617*1E6
2553 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2554 time_T2_2 = 0.05
2555 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2556 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05]
2557
2558 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2]
2559
2560
2561 exps = [exp_1, exp_2]
2562
2563 spins = [
2564 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ],
2565 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ]
2566 ]
2567
2568
2569 ds.data = [model_create, model_analyse, spins, exps]
2570
2571
2572 ds.tmpdir = ds.tmpdir
2573
2574
2575
2576 ds.resdir = ds.tmpdir
2577
2578
2579 ds.r20_from_min_r2eff = True
2580
2581
2582 ds.insignificance = 0.0
2583
2584
2585 ds.GRID_INC = 13
2586
2587
2588 ds.do_cluster = True
2589
2590
2591
2592 ds.set_func_tol = 1e-8
2593
2594
2595
2596 ds.set_max_iter = 10000
2597
2598
2599 ds.verbosity = 1
2600
2601
2602 ds.rel_change = 0.05
2603
2604
2605 ds.plot_curves = False
2606
2607
2608 ds.sherekhan_input = False
2609
2610
2611 ds.opendx = False
2612
2613
2614 ds.r2eff_err = 0.1
2615
2616
2617 ds.print_res = False
2618
2619
2620 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2621
2622 cur_spins = ds.data[2]
2623
2624 for i in range(len(cur_spins)):
2625 res_name, res_num, spin_name, params = cur_spins[i]
2626 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2627 cur_spin = return_spin(cur_spin_id)
2628
2629 grid_params = ds.grid_results[i][3]
2630
2631
2632 min_params = ds.clust_results[i][3]
2633
2634 print("For spin: '%s'"%cur_spin_id)
2635 for mo_param in cur_spin.params:
2636
2637 if isinstance(getattr(cur_spin, mo_param), dict):
2638 grid_r2 = grid_params[mo_param]
2639 min_r2 = min_params[mo_param]
2640 set_r2 = params[mo_param]
2641 for key, val in list(set_r2.items()):
2642 grid_r2_frq = grid_r2[key]
2643 min_r2_frq = min_r2[key]
2644 set_r2_frq = set_r2[key]
2645 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2646 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2647 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) )
2648 if rel_change > ds.rel_change:
2649 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2650 print("###################################")
2651
2652
2653 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1)
2654 else:
2655 grid_val = grid_params[mo_param]
2656 min_val = min_params[mo_param]
2657 set_val = params[mo_param]
2658 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2659 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) )
2660 if rel_change > ds.rel_change:
2661 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2662 print("###################################")
2663
2664
2665 if mo_param == 'dw':
2666 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2667 elif mo_param == 'kex':
2668 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2669 elif mo_param == 'pA':
2670 self.assertAlmostEqual(set_val, min_val, 2)
2671
2672
2674 """Test synthetic cpmg data, calling the dx.map function with one or two points.
2675
2676 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
2677 """
2678
2679
2680
2681
2682
2683 model_create = MODEL_NS_CPMG_2SITE_EXPANDED
2684 model_analyse = 'CR72'
2685
2686 sfrq_1 = 599.8908617*1E6
2687 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2688 time_T2_1 = 0.06
2689 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2690 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0]
2691 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1]
2692
2693 sfrq_2 = 499.8908617*1E6
2694 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2695 time_T2_2 = 0.05
2696 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2697 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0]
2698 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2]
2699
2700
2701 exps = [exp_1, exp_2]
2702
2703 spins = [
2704 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ]
2705 ]
2706
2707
2708 ds.data = [model_create, model_analyse, spins, exps]
2709
2710
2711 ds.tmpdir = ds.tmpdir
2712
2713
2714
2715 ds.resdir = ds.tmpdir
2716
2717
2718 ds.r20_from_min_r2eff = True
2719
2720
2721 ds.insignificance = 0.0
2722
2723
2724 ds.GRID_INC = None
2725
2726
2727 ds.do_cluster = False
2728
2729
2730
2731 ds.set_func_tol = 1e-9
2732
2733
2734
2735 ds.set_max_iter = 1000
2736
2737
2738 ds.verbosity = 1
2739
2740
2741 ds.rel_change = 0.05
2742
2743
2744 ds.plot_curves = False
2745
2746
2747 ds.sherekhan_input = False
2748
2749
2750 ds.opendx = False
2751
2752
2753 ds.r2eff_err = 0.1
2754
2755
2756 ds.print_res = False
2757
2758
2759 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2760
2761
2762 cur_spins = ds.data[2]
2763
2764
2765 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse)
2766 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle)
2767 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP)
2768
2769
2770 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff')
2771
2772
2773 self.interpreter.relax_disp.select_model(model=model_analyse)
2774
2775
2776 ds.dx_inc = 4
2777 ds.dx_params = ['dw', 'pA', 'kex']
2778
2779 res_name, res_num, spin_name, params = cur_spins[0]
2780 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2781 cur_spin = return_spin(cur_spin_id)
2782
2783 print("Params for dx map is")
2784 print(ds.dx_params)
2785 print("Point param for dx map is")
2786 print(ds.dx_set_val)
2787 cur_model = model_analyse.replace(' ', '_')
2788 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
2789 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_'))
2790 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True)
2791
2792
2793
2794 map_cfg = ds.tmpdir+sep+file_name_map+".cfg"
2795 map_net = ds.tmpdir+sep+file_name_map+".net"
2796 map_general = ds.tmpdir+sep+file_name_map+".general"
2797 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir)
2798 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir)
2799
2800 point_general = ds.tmpdir+sep+file_name_point+".general"
2801 point_point = ds.tmpdir+sep+file_name_point
2802 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir)
2803
2804
2805 self.assert_(access(map_cfg, F_OK))
2806 self.assert_(access(map_net, F_OK))
2807 self.assert_(access(map_general, F_OK))
2808 self.assert_(access(map_par, F_OK))
2809 self.assert_(access(map_plot, F_OK))
2810 self.assert_(access(point_general, F_OK))
2811 self.assert_(access(point_point, F_OK))
2812 self.assert_(access(point_par, F_OK))
2813
2814
2815
2816 print("\nChecking the dx map .cfg file.")
2817 res_file = [
2818 '//'+"\n",
2819 '//'+"\n",
2820 '// time: Thu May 8 18:55:31 2014'+"\n",
2821 '//'+"\n",
2822 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n",
2823 '//'+"\n",
2824 '//'+"\n",
2825 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n",
2826 '// title: value = Control Panel'+"\n",
2827 '//'+"\n",
2828 '// workspace: width = 251, height = 142'+"\n",
2829 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n",
2830 '//'+"\n",
2831 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n",
2832 '// selections: maximum = 2, current = 0 '+"\n",
2833 '// option[0]: name = "Colour", value = 1'+"\n",
2834 '// option[1]: name = "Grey", value = 2'+"\n",
2835 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n",
2836 '// label: value = Colour Selector'+"\n",
2837 '//'+"\n",
2838 '// node Image[3]:'+"\n",
2839 '// title: value = Surface'+"\n",
2840 '// depth: value = 24'+"\n",
2841 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n",
2842 ]
2843 file = open(map_cfg, 'r')
2844 lines = file.readlines()
2845 file.close()
2846 for i in range(len(res_file)):
2847
2848 if i == 2:
2849 continue
2850 self.assertEqual(res_file[i], lines[i])
2851
2852 print("\nChecking the dx map .general file.")
2853 res_file = [
2854 'file = CR72_map_1_N'+"\n",
2855 'grid = 5 x 5 x 5'+"\n",
2856 'format = ascii'+"\n",
2857 'interleaving = field'+"\n",
2858 'majority = row'+"\n",
2859 'field = data'+"\n",
2860 'structure = scalar'+"\n",
2861 'type = float'+"\n",
2862 'dependency = positions'+"\n",
2863 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n",
2864 ''+"\n",
2865 'end'+"\n",
2866 ]
2867 file = open(map_general, 'r')
2868 lines = file.readlines()
2869 file.close()
2870 for i in range(len(res_file)):
2871
2872
2873
2874 self.assertEqual(res_file[i], lines[i])
2875
2876 print("\nChecking the dx point .general file.")
2877 res_file = [
2878 'file = CR72_point_1_N'+"\n",
2879 'points = 2'+"\n",
2880 'format = ascii'+"\n",
2881 'interleaving = field'+"\n",
2882 'field = locations, field0'+"\n",
2883 'structure = 3-vector, scalar'+"\n",
2884 'type = float, float'+"\n",
2885 ''+"\n",
2886 'end'+"\n",
2887 ]
2888 file = open(point_general, 'r')
2889 lines = file.readlines()
2890 file.close()
2891 for i in range(len(res_file)):
2892
2893
2894
2895 self.assertEqual(res_file[i], lines[i])
2896
2897 print("\nChecking the dx point point file.")
2898 res_file = [
2899 '0.8 3.92 0.39964 1'+"\n",
2900 '0.76981 3.9169 0.41353 1'+"\n",
2901 ]
2902 file = open(point_point, 'r')
2903 lines = file.readlines()
2904 file.close()
2905 for i in range(len(res_file)):
2906
2907
2908
2909 self.assertEqual(res_file[i], lines[i])
2910
2911 print("\nChecking the dx point par file.")
2912 res_file = [
2913 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n",
2914 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n",
2915 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n",
2916 ]
2917 res_file2 = [
2918 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n",
2919 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n",
2920 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n",
2921 ]
2922 file = open(point_par, 'r')
2923 lines = file.readlines()
2924 file.close()
2925 for i in range(len(res_file)):
2926 if lines[i] != res_file[i] and lines[i] != res_file2[i]:
2927 self.assertEqual(res_file[i], lines[i])
2928
2929 print("\nChecking the matplotlib surface plot file.")
2930 res_file = [
2931 'from copy import deepcopy'+"\n",
2932 'import numpy as np'+"\n",
2933 'import scipy.interpolate'+"\n",
2934 'from numpy.ma import masked_where'+"\n",
2935 ''+"\n",
2936 'from mpl_toolkits.mplot3d import axes3d'+"\n",
2937 'import matplotlib.pyplot as plt'+"\n",
2938 'from matplotlib import cm'+"\n",
2939 ''+"\n",
2940 '# Open file and get header.'+"\n",
2941 'mapfile_name = "%s.par"'%file_name_map+"\n",
2942 'pointfile_name = "%s.par"'%file_name_point+"\n",
2943 ''+"\n",
2944 ]
2945 file = open(map_plot, 'r')
2946 lines = file.readlines()
2947 file.close()
2948 for i in range(len(res_file)):
2949 self.assertEqual(res_file[i], lines[i])
2950
2951
2953 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data."""
2954
2955
2956 self.interpreter.reset()
2957
2958
2959 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'
2960 self.interpreter.state.load(data_path+sep+'r2eff_values')
2961
2962
2963 curve_type = get_curve_type(id='500_133.33.in')
2964 self.assertEqual(curve_type, 'fixed time')
2965
2966
2968 """Test the curve type detection using the 'M61' exponential test data."""
2969
2970
2971 self.interpreter.reset()
2972
2973
2974 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61'
2975 self.interpreter.state.load(data_path+sep+'r2eff_values')
2976
2977
2978 curve_type = get_curve_type(id='nu_2000_ncyc9')
2979 self.assertEqual(curve_type, 'exponential')
2980
2981
2983 """Test the curve type detection using the 'TP02' fixed time test data."""
2984
2985
2986 self.interpreter.reset()
2987
2988
2989 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'
2990 self.interpreter.state.load(data_path+sep+'r2eff_values')
2991
2992
2993 curve_type = get_curve_type(id='nu_1000.0_500MHz')
2994 self.assertEqual(curve_type, 'fixed time')
2995
2996
2998 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data."""
2999
3000
3001 ds.fixed = True
3002
3003
3004 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py')
3005
3006
3007 i0 = [100000.0, 20000.0]
3008 r1rho_prime = [2.25, 24.0]
3009 pA = 0.7
3010 kex = 1000.0
3011 delta_omega = [1.0, 2.0]
3012 phi_ex = []
3013 for i in range(2):
3014 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2)
3015
3016
3017 self.interpreter.pipe.switch('DPL94 - relax_disp')
3018 spin_index = 0
3019 for spin, spin_id in spin_loop(return_id=True):
3020
3021 print("\nSpin %s." % spin_id)
3022
3023
3024 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2)
3025 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2)
3026 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
3027
3028
3029 spin_index += 1
3030
3031
3033 """Test making dx_map for residues under clustered calculation.
3034
3035 This uses CPMG data from:
3036 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE
3037 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations.
3038 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>}
3039 """
3040
3041
3042 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011'
3043
3044
3045 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins')
3046
3047
3048 cur_spin_id = ":%i@%s"%(52, 'N')
3049 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')
3050
3051
3052 cur_spin = return_spin(cur_spin_id)
3053
3054
3055 pre_chi2 = cur_spin.chi2
3056
3057
3058
3059 self.interpreter.minimise.calculate()
3060
3061
3062 calc_chi2 = cur_spin.chi2
3063
3064
3065 self.assertAlmostEqual(pre_chi2, calc_chi2)
3066
3067
3068 dx_inc = 2
3069 dx_inc_sides = dx_inc / 2
3070
3071 dx_params = ['dw', 'pA', 'kex']
3072 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex]
3073
3074 print("Params for dx map is")
3075 print(dx_params)
3076 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2)
3077 print(dx_point_clustered_min)
3078
3079
3080 cur_model = 'CR72'
3081 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str)
3082 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str)
3083
3084
3085 param_delta = 0.1
3086
3087
3088 lower = []
3089 upper = []
3090 for i, param_val in enumerate(dx_point_clustered_min):
3091 param = dx_params[i]
3092 step_val = param_delta * param_val
3093 step_length = step_val * dx_inc_sides
3094
3095
3096 low_val = param_val - step_length
3097 lower.append(low_val)
3098
3099 upp_val = param_val + step_length
3100 upper.append(upp_val)
3101
3102 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val))
3103
3104
3105
3106 dx_param_indexes = dx_inc + 1
3107 dx_point_index = dx_inc_sides + 1
3108
3109
3110 line = 1
3111 for i in range(1, dx_param_indexes + 1):
3112 for j in range(1, dx_param_indexes + 1):
3113 for k in range(1, dx_param_indexes + 1):
3114 if i == dx_point_index and j == dx_point_index and k == dx_point_index:
3115 line_chi2 = line
3116
3117 line += 1
3118
3119
3120 result_dir = self.tmpdir
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point)
3131
3132
3133 nr_chi2_val = dx_param_indexes**3
3134 print("Nr of chi2 calculations are=%i"%nr_chi2_val)
3135 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) )
3136
3137
3138
3139 map_name = get_file_path(file_name=file_name_map, dir=result_dir)
3140 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir)
3141 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir)
3142 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir)
3143
3144 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir)
3145 point_point = get_file_path(file_name=file_name_point, dir=result_dir)
3146
3147
3148 self.assert_(access(map_cfg, F_OK))
3149 self.assert_(access(map_net, F_OK))
3150 self.assert_(access(map_general, F_OK))
3151 self.assert_(access(point_general, F_OK))
3152 self.assert_(access(point_point, F_OK))
3153
3154
3155 get_data = extract_data(file=map_name)
3156
3157
3158 test = float(get_data[line_chi2-1][0])
3159
3160
3161 self.assertAlmostEqual(test, pre_chi2, 6)
3162
3163
3165 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file.
3166
3167 U{Task #7860<https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value.
3168
3169 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride).
3170 """
3171
3172
3173 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting'
3174
3175
3176 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2')
3177
3178
3179 cur_spin_id = ":%i@%s"%(65, 'N')
3180 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')
3181
3182
3183 cur_spin = return_spin(cur_spin_id)
3184
3185
3186 pre_chi2 = cur_spin.chi2
3187
3188
3189
3190 self.interpreter.minimise.calculate()
3191
3192
3193 calc_chi2 = cur_spin.chi2
3194
3195
3196 self.assertAlmostEqual(pre_chi2, calc_chi2)
3197
3198
3199 dx_inc = 2
3200 dx_params = ['dw', 'k_AB', 'r2a']
3201 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']]
3202
3203 print("Params for dx map is")
3204 print(dx_params)
3205 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2)
3206 print(dx_point_clustered_min)
3207
3208
3209 cur_model = 'TSMFK01'
3210 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str)
3211 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str)
3212
3213
3214 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]]
3215 upper = [19.0, 2.4, 9.5]
3216
3217
3218 result_dir = self.tmpdir
3219
3220
3221
3222
3223
3224
3225 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True)
3226
3227
3228 nr_chi2_val = (dx_inc + 1)**3
3229 print("Nr of chi2 calculations are=%i"%nr_chi2_val)
3230 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) )
3231
3232
3233
3234 map_name = get_file_path(file_name=file_name_map, dir=result_dir)
3235 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir)
3236 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir)
3237 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir)
3238 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir)
3239
3240 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir)
3241 point_point = get_file_path(file_name=file_name_point, dir=result_dir)
3242
3243
3244 self.assert_(access(map_cfg, F_OK))
3245 self.assert_(access(map_net, F_OK))
3246 self.assert_(access(map_general, F_OK))
3247 self.assert_(access(map_par, F_OK))
3248 self.assert_(access(point_general, F_OK))
3249 self.assert_(access(point_point, F_OK))
3250
3251 print("\nParams for dx map is")
3252 print(dx_params)
3253 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2)
3254 print(dx_point_clustered_min, "\n")
3255
3256
3257 get_data = extract_data(file=map_par)
3258
3259
3260 test = float(get_data[1][9])
3261
3262
3263 if test < pre_chi2:
3264 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test))
3265 for line in get_data:
3266 print(line)
3267
3268
3269
3270
3271
3272
3273
3274
3275
3277 """Test the user function for estimating R2eff errors from exponential curve fitting.
3278
3279 This follows Task 7822.
3280 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting.
3281
3282 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
3283 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
3284 """
3285
3286
3287 cluster_ids = [
3288 ":13@N",
3289 ":15@N",
3290 ":16@N",
3291 ":25@N",
3292 ":26@N",
3293 ":28@N",
3294 ":39@N",
3295 ":40@N",
3296 ":41@N",
3297 ":43@N",
3298 ":44@N",
3299 ":45@N",
3300 ":49@N",
3301 ":52@N",
3302 ":53@N"]
3303
3304
3305 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False)
3306
3307
3308 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
3309
3310
3311 GRID_INC = None
3312
3313
3314 MC_NUM = 3
3315
3316
3317 MODSEL = 'AIC'
3318
3319
3320
3321 OPT_FUNC_TOL = 1e-25
3322 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
3323 OPT_MAX_ITERATIONS = 10000000
3324 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
3325
3326 result_dir_name = ds.tmpdir
3327
3328
3329 for curspin in cluster_ids:
3330 self.interpreter.relax_disp.cluster('free spins', curspin)
3331
3332 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
3333
3334
3335
3336
3337
3338
3339
3340
3341 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
3342
3343
3344
3345 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
3346
3347
3348 check_intensity_errors()
3349
3350
3351 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1)
3352
3353
3354 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1)
3355
3356
3357 self.interpreter.relax_disp.r2eff_err_estimate()
3358
3359 r1_fit = True
3360
3361
3362 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit)
3363
3364
3365 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3366
3367
3369 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu.
3370
3371 This follows Task 7822.
3372 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting.
3373
3374 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
3375 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
3376 """
3377
3378
3379 cluster_ids = [
3380 ":13@N",
3381 ":15@N",
3382 ":16@N",
3383 ":25@N",
3384 ":26@N",
3385 ":28@N",
3386 ":39@N",
3387 ":40@N",
3388 ":41@N",
3389 ":43@N",
3390 ":44@N",
3391 ":45@N",
3392 ":49@N",
3393 ":52@N",
3394 ":53@N"]
3395
3396
3397
3398 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep
3399
3400
3401 pipe_name = 'base pipe'
3402 pipe_bundle = 'relax_disp'
3403 pipe_type = 'relax_disp'
3404
3405
3406 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type)
3407
3408 file = data_path + '1_setup_r1rho_GUI.py'
3409 self.interpreter.script(file=file, dir=None)
3410
3411
3412 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
3413
3414
3415 GRID_INC = None
3416
3417
3418
3419
3420 EXP_MC_NUM = -1
3421
3422
3423 MC_NUM = 3
3424
3425
3426 MODSEL = 'AIC'
3427
3428
3429
3430 OPT_FUNC_TOL = 1e-25
3431 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
3432 OPT_MAX_ITERATIONS = 10000000
3433 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
3434
3435
3436
3437
3438
3439
3440
3441
3442 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False)
3443
3444
3445
3446
3447
3448
3449
3450
3451 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
3452
3453
3454 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3455 print(spin_id)
3456
3457 result_dir_name = self.tmpdir
3458 r1_fit = True
3459
3460
3461 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit)
3462
3463
3464 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3465
3466
3468 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods.
3469 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations.
3470
3471 This follows Task 7822.
3472 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting.
3473
3474 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
3475 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
3476
3477 NOTE: The difference in the methods was due to a bug in relax!
3478 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected.
3479
3480 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong.
3481 """
3482
3483
3484 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff"
3485
3486
3487 self.interpreter.pipe.create('MC_2000', 'relax_disp')
3488
3489
3490 self.interpreter.results.read(prev_data_path + sep + 'results')
3491
3492
3493 my_dic = {}
3494 param_key_list = []
3495
3496
3497 do_boot = True
3498 if do_boot:
3499 min_algor = 'Newton'
3500 min_options = ()
3501 sim_boot = 200
3502 scaling_list = [1.0, 1.0]
3503
3504
3505 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3506
3507 my_dic[spin_id] = {}
3508
3509
3510 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim):
3511
3512 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
3513
3514 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
3515 r2eff_sim_point = r2eff_sim[param_key]
3516 i0_sim_point = cur_spin.r2eff_sim[i][param_key]
3517
3518
3519
3520
3521 self.assert_(r2eff_sim_point > 0.0)
3522 self.assert_(i0_sim_point > 0.0)
3523
3524
3525 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3526
3527 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
3528
3529 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
3530
3531 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
3532
3533
3534 r2eff_sim_l = []
3535 i0_sim_l = []
3536 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim):
3537 i0_sim = cur_spin.i0_sim[i]
3538
3539 r2eff_sim_i = r2eff_sim[param_key]
3540 r2eff_sim_l.append(r2eff_sim_i)
3541 i0_sim_i = i0_sim[param_key]
3542 i0_sim_l.append(i0_sim_i)
3543
3544
3545 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1)
3546 i0_sim_err = std(asarray(i0_sim_l), ddof=1)
3547
3548
3549 param_key_list.append(param_key)
3550
3551
3552 my_dic[spin_id][param_key] = {}
3553
3554
3555 r2eff = getattr(cur_spin, 'r2eff')[param_key]
3556 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key]
3557 i0 = getattr(cur_spin, 'i0')[param_key]
3558 i0_err = getattr(cur_spin, 'i0_err')[param_key]
3559
3560
3561 my_dic[spin_id][param_key]['r2eff'] = r2eff
3562 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err
3563 my_dic[spin_id][param_key]['i0'] = i0
3564 my_dic[spin_id][param_key]['i0_err'] = i0_err
3565 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err
3566 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err
3567
3568
3569 self.assertAlmostEqual(r2eff_sim_err, r2eff_err)
3570 self.assertAlmostEqual(i0_sim_err, i0_err)
3571
3572 if do_boot:
3573 values = []
3574 errors = []
3575 times = []
3576 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point):
3577 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time))
3578 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True))
3579 times.append(time)
3580
3581
3582 values = asarray(values)
3583 errors = asarray(errors)
3584 times = asarray(times)
3585
3586 R_m_sim_l = []
3587 I0_m_sim_l = []
3588 for j in range(sim_boot):
3589 if j in range(0, 100000, 100):
3590 print("Simulation %i"%j)
3591
3592
3593
3594 I_err = []
3595 for j, error in enumerate(errors):
3596 I_error = gauss(values[j], error)
3597 I_err.append(I_error)
3598
3599 I_err = asarray(I_err)
3600
3601 x0 = [r2eff, i0]
3602 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list)
3603
3604 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0)
3605 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j
3606 R_m_sim_l.append(R_m_sim_j)
3607 I0_m_sim_l.append(I0_m_sim_j)
3608
3609
3610 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1)
3611 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1)
3612 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim
3613 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim
3614
3615
3616
3617 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est')
3618 self.interpreter.pipe.switch(pipe_name='r2eff_est')
3619
3620
3621 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3622 delattr(cur_spin, 'r2eff_err')
3623 delattr(cur_spin, 'i0_err')
3624
3625
3626 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
3627
3628
3629 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0)
3630
3631 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3632
3633 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
3634
3635 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
3636
3637 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
3638
3639
3640 r2eff_est = getattr(cur_spin, 'r2eff')[param_key]
3641 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key]
3642 i0_est = getattr(cur_spin, 'i0')[param_key]
3643 i0_err_est = getattr(cur_spin, 'i0_err')[param_key]
3644
3645
3646 r2eff = my_dic[spin_id][param_key]['r2eff']
3647 r2eff_err = my_dic[spin_id][param_key]['r2eff_err']
3648 i0 = my_dic[spin_id][param_key]['i0']
3649 i0_err = my_dic[spin_id][param_key]['i0_err']
3650 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim']
3651 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim']
3652
3653 if do_boot:
3654 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot']
3655 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot']
3656 else:
3657 r2eff_boot_err = 0.0
3658 i0_boot_err = 0.0
3659
3660 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) )
3661 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ),
3662 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) )
3663
3664
3665
3666 estimate_r2eff(method='scipy.optimize.leastsq')
3667
3668 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False)
3669 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True)
3670
3671 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False)
3672 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True)
3673
3674 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False)
3675 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True)
3676
3677 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False)
3678 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True)
3679
3680 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False)
3681 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3682
3683
3684
3686 """Test the relaxation dispersion 'exp_fit' model curve fitting."""
3687
3688
3689 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py')
3690
3691
3692 res_data = [
3693 [15., 10., 20000., 25000.],
3694 [12., 11., 50000., 51000.],
3695 [17., 9., 100000., 96000.]
3696 ]
3697
3698
3699 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw']
3700
3701
3702 for i in range(len(res_data)):
3703
3704 print("\nResidue number %s." % (i+1))
3705
3706
3707 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2)
3708 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2)
3709 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3)
3710 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3)
3711
3712
3713 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0)
3714 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0)
3715 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0)
3716 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0)
3717
3718
3719 for param in blacklist:
3720 print("\tChecking for the absence of the '%s' parameter." % param)
3721 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param))
3722
3723
3724 self.assert_(hasattr(cdp, 'clustering'))
3725 keys = ['free spins', 'cluster']
3726 for key in keys:
3727 self.assert_(key in cdp.clustering)
3728 self.assert_('test' not in cdp.clustering)
3729 self.assertEqual(cdp.clustering['free spins'], [':2@N'])
3730 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3731
3732
3734 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step."""
3735
3736 times = array([ 0.7, 1., 0.8, 0.4, 0.9])
3737 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341])
3738 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736])
3739
3740 scaling_list = [1.0, 1.0]
3741 setup(num_params=2, num_times=len(times), values=I, sd=errors, relax_times=times, scaling_matrix=scaling_list)
3742
3743 R = - 500.
3744 I0 = 1000.
3745 params = [R, I0]
3746
3747 chi2 = func(params)
3748
3749 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2))
3750 self.assertNotEqual(chi2, inf)
3751
3752
3863
3864
3866 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data.
3867
3868 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
3869 """
3870
3871
3872 ds.models = [
3873 MODEL_NOREX,
3874 MODEL_LM63,
3875 MODEL_CR72,
3876 MODEL_IT99
3877 ]
3878
3879
3880 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py')
3881 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True)
3882
3883
3884 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
3885 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
3886
3887
3888 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
3889 spin70 = return_spin(":70")
3890 spin71 = return_spin(":71")
3891 print("\n\nOptimised parameters:\n")
3892 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
3893 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
3894 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
3895 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
3896 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3)
3897 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3)
3898 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3)
3899 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3)
3900 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3)
3901 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3)
3902
3903
3904 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp')
3905 spin70 = return_spin(":70")
3906 spin71 = return_spin(":71")
3907 print("\n\nOptimised parameters:\n")
3908 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
3909 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
3910 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
3911 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex))
3912 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
3913 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
3914 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2)
3915 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2)
3916 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3)
3917 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3)
3918 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3)
3919 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3)
3920 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3)
3921 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3)
3922 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3)
3923 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3)
3924
3925
3926 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
3927 spin70 = return_spin(":70")
3928 spin71 = return_spin(":71")
3929 print("\n\nOptimised parameters:\n")
3930 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
3931 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
3932 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
3933 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
3934 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
3935 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
3936 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
3937 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3)
3938 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2)
3939 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3)
3940 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3)
3941 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3)
3942 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3)
3943 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3)
3944 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3)
3945 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3)
3946 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2)
3947 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3)
3948 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
3949
3950
3952 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data.
3953
3954 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
3955 """
3956
3957
3958 ds.models = [
3959 MODEL_NOREX,
3960 MODEL_CR72,
3961 MODEL_NS_CPMG_2SITE_EXPANDED
3962 ]
3963 ds.numeric_only = True
3964
3965
3966 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py')
3967
3968
3969 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
3970 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
3971
3972
3973 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
3974 spin70 = return_spin(":70")
3975 spin71 = return_spin(":71")
3976 print("\n\nOptimised parameters:\n")
3977 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
3978 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
3979 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
3980 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
3981 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3)
3982 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3)
3983 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3)
3984 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3)
3985 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3)
3986 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3)
3987
3988
3989 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
3990 spin70 = return_spin(":70")
3991 spin71 = return_spin(":71")
3992 print("\n\nOptimised parameters:\n")
3993 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
3994 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
3995 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
3996 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
3997 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
3998 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
3999 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4000 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3)
4001 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2)
4002 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3)
4003 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3)
4004 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3)
4005 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3)
4006 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3)
4007 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3)
4008 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3)
4009 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2)
4010 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3)
4011 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4012
4013
4014 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp')
4015 spin70 = return_spin(":70")
4016 spin71 = return_spin(":71")
4017 print("\n\nOptimised parameters:\n")
4018 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4019 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4020 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4021 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4022 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4023 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4024 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4025 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3)
4026 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3)
4027 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3)
4028 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3)
4029 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3)
4030 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3)
4031 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3)
4032 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3)
4033 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3)
4034 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2)
4035 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3)
4036 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3)
4037
4038
4039 self.interpreter.pipe.switch(pipe_name='final - relax_disp')
4040 spin70 = return_spin(":70")
4041 spin71 = return_spin(":71")
4042 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded')
4043 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4044
4045
4047 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities).
4048
4049 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4050 """
4051
4052
4053 ds.models = [
4054 MODEL_NOREX,
4055 MODEL_LM63,
4056 MODEL_CR72,
4057 MODEL_IT99
4058 ]
4059
4060
4061 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py')
4062 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True)
4063
4064
4065 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4066 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4067
4068
4069 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
4070 spin70 = return_spin(":70")
4071 spin71 = return_spin(":71")
4072 print("\n\nOptimised parameters:\n")
4073 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4074 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4075 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4076 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4077 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3)
4078 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3)
4079 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3)
4080 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3)
4081 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3)
4082 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3)
4083
4084
4085 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp')
4086 spin70 = return_spin(":70")
4087 spin71 = return_spin(":71")
4088 print("\n\nOptimised parameters:\n")
4089 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4090 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4091 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4092 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex))
4093 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4094 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4095 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2)
4096 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2)
4097 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3)
4098 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3)
4099 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3)
4100 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3)
4101 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3)
4102 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3)
4103 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3)
4104 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3)
4105
4106
4107 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
4108 spin70 = return_spin(":70")
4109 spin71 = return_spin(":71")
4110 print("\n\nOptimised parameters:\n")
4111 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4112 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4113 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4114 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4115 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4116 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4117 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4118 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3)
4119 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2)
4120 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3)
4121 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3)
4122 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3)
4123 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3)
4124 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3)
4125 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3)
4126 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3)
4127 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2)
4128 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3)
4129 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4130
4131
4133 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing.
4134
4135 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4136 """
4137
4138
4139 ds.models = [
4140 MODEL_R2EFF,
4141 MODEL_NOREX,
4142 MODEL_CR72,
4143 MODEL_NS_CPMG_2SITE_EXPANDED
4144 ]
4145
4146
4147 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py')
4148 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True)
4149
4150
4151 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4152 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4153
4154
4155 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
4156 spin4 = return_spin(":4")
4157 spin70 = return_spin(":70")
4158 spin71 = return_spin(":71")
4159 print("\n\nOptimised parameters:\n")
4160 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)"))
4161 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1]))
4162 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2]))
4163 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2))
4164 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3)
4165 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3)
4166 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3)
4167 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3)
4168 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3)
4169 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3)
4170 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3)
4171 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3)
4172
4173
4174 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
4175 spin4 = return_spin(":4")
4176 spin70 = return_spin(":70")
4177 spin71 = return_spin(":71")
4178 print("\n\nOptimised parameters:\n")
4179 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)"))
4180 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1]))
4181 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2]))
4182 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA))
4183 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw))
4184 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex))
4185 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2))
4186 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2)
4187 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3)
4188
4189 self.assertAlmostEqual(spin4.dw, 0.0, 2)
4190 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3)
4191 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3)
4192 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3)
4193 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3)
4194 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3)
4195 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3)
4196 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3)
4197 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3)
4198 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3)
4199 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3)
4200 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2)
4201 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3)
4202 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4203
4204
4206 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model.
4207
4208 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4209 """
4210
4211
4212 self.setup_hansen_cpmg_data(model='CR72')
4213
4214
4215 spin70 = return_spin(":70")
4216 spin71 = return_spin(":71")
4217
4218
4219 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4220 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4221
4222
4223 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0}
4224 spin70.pA = 0.9
4225 spin70.dw = 6.0
4226 spin70.kex = 1500.0
4227 spin71.r2 = {r20_key1: 5, r20_key2: 9.0}
4228 spin71.pA = 0.9
4229 spin71.dw = 4.0
4230 spin71.kex = 1900.0
4231
4232
4233 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
4234
4235
4236 print("\n\nOptimised parameters:\n")
4237 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4238 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4239 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4240 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4241 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4242 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4243 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4244
4245
4246 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4)
4247 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2)
4248 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4)
4249 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3)
4250 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3)
4251 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4)
4252
4253
4254 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4)
4255 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4)
4256 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4)
4257 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4)
4258 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4)
4259
4260
4261 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4262 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4263
4264
4265 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4266 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4267
4268
4270 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model.
4271
4272 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4273 """
4274
4275
4276 self.setup_hansen_cpmg_data(model='CR72 full')
4277
4278
4279 spin70 = return_spin(":70")
4280 spin71 = return_spin(":71")
4281
4282
4283 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4284 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4285
4286
4287 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0}
4288 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0}
4289 spin70.pA = 0.9
4290 spin70.dw = 6.0
4291 spin70.kex = 1500.0
4292 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0}
4293 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0}
4294 spin71.pA = 0.9
4295 spin71.dw = 4.0
4296 spin71.kex = 1900.0
4297
4298
4299 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
4300
4301
4302 print("\n\nOptimised parameters:\n")
4303 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4304 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1]))
4305 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1]))
4306 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2]))
4307 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2]))
4308 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4309 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4310 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4311 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4312
4313
4314 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4)
4315 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4)
4316 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4)
4317 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4)
4318 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4)
4319 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4)
4320 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4)
4321 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4)
4322
4323
4324 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4)
4325 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4)
4326 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4)
4327 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4)
4328 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4)
4329 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4)
4330
4331
4332 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4333 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4334
4335
4336 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4337 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4338
4339
4341 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model.
4342
4343 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4344 """
4345
4346
4347 self.setup_hansen_cpmg_data(model='IT99')
4348
4349
4350 spin70 = return_spin(":70")
4351 spin71 = return_spin(":71")
4352
4353
4354 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4355 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4356
4357
4358 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6}
4359 spin70.dw = 10.0
4360 spin70.pA = 0.5
4361 spin70.tex = 1000.09
4362 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0}
4363 spin71.dw = 10.0
4364 spin71.pA = 0.95
4365 spin71.tex = 0.1
4366
4367
4368 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1)
4369
4370
4371 print("\n\nOptimised parameters:\n")
4372 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4373 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4374 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4375 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4376 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4377 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex))
4378 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4379
4380
4381 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4)
4382 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4)
4383 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4)
4384 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4)
4385 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4)
4386 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4)
4387
4388
4389 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4)
4390 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4)
4391 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4)
4392 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3)
4393 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4)
4394 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4395
4396
4398 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model.
4399
4400 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4401 """
4402
4403
4404 self.setup_hansen_cpmg_data(model='LM63')
4405
4406
4407 spin70 = return_spin(":70")
4408 spin71 = return_spin(":71")
4409
4410
4411 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4412 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4413
4414
4415 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0}
4416 spin70.phi_ex = 0.3
4417 spin70.kex = 5000.0
4418 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0}
4419 spin71.phi_ex = 0.1
4420 spin71.kex = 2500.0
4421
4422
4423 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1)
4424
4425
4426 print("\n\nOptimised parameters:\n")
4427 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4428 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4429 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4430 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex))
4431 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4432 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4433
4434
4435 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099)
4436 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6)
4437 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449)
4438 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6)
4439 self.assertAlmostEqual(spin70.chi2, 363.534044873483)
4440
4441
4442 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5)
4443 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5)
4444 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5)
4445 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4446
4447
4449 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model.
4450
4451 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4452 """
4453
4454
4455 self.setup_hansen_cpmg_data(model='LM63 3-site')
4456
4457
4458 spin70 = return_spin(":70")
4459 spin71 = return_spin(":71")
4460
4461
4462 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4463 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4464
4465
4466 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107}
4467 spin70.phi_ex_B = 0.14872003058250227
4468 spin70.phi_ex_C = 0.1319419923472704
4469 spin70.kB = 4103.672910444741
4470 spin70.kC = 7029.001690726248
4471 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575}
4472 spin71.phi_ex_B = 0.04013553485505605
4473 spin71.phi_ex_C = 0.020050748406928887
4474 spin71.kB = 4045.3007136121364
4475 spin71.kC = 3586.38798270774
4476
4477
4478
4479
4480
4481 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1)
4482
4483
4484 print("\n\nOptimised parameters:\n")
4485 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4486 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4487 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4488 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B))
4489 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C))
4490 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB))
4491 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC))
4492 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4493
4494
4495 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5)
4496 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6)
4497 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5)
4498 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5)
4499 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6)
4500 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6)
4501 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5)
4502
4503
4504 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5)
4505 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5)
4506 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5)
4507 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5)
4508 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5)
4509 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4510
4511
4513 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model.
4514
4515 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4516 """
4517
4518
4519 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D')
4520
4521
4522 spin70 = return_spin(":70")
4523 spin71 = return_spin(":71")
4524
4525
4526 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4527 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4528
4529
4530 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427}
4531 spin70.pA = 0.9897754407
4532 spin70.dw = 5.642418428
4533 spin70.kex = 1743.666375
4534 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959}
4535 spin71.pA = 0.9968032899
4536 spin71.dw = 4.577891393
4537 spin71.kex = 1830.044597
4538
4539
4540 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1)
4541
4542
4543 print("\n\nOptimised parameters:\n")
4544 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4545 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4546 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4547 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4548 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4549 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4550 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4551
4552
4553 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4)
4554 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4)
4555 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4)
4556 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4)
4557 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4)
4558 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4)
4559
4560
4561 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4)
4562 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4)
4563 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4)
4564 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4)
4565 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4)
4566 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4)
4567
4568
4569 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4570 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4571
4572
4573 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4574 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4575
4576
4578 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model.
4579
4580 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4581 """
4582
4583
4584 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full')
4585
4586
4587 spin70 = return_spin(":70")
4588 spin71 = return_spin(":71")
4589
4590
4591 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4592 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4593
4594
4595 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687}
4596 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395}
4597 spin70.pA = 0.9884781357
4598 spin70.dw = 5.456507396
4599 spin70.kex = 1906.521189
4600 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0}
4601 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0}
4602 spin71.pA = 0.986709616684097
4603 spin71.dw = 2.09245158280905
4604 spin71.kex = 2438.2766211401
4605
4606
4607 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1)
4608
4609
4610 print("\n\nOptimised parameters:\n")
4611 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4612 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1]))
4613 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1]))
4614 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2]))
4615 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2]))
4616 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4617 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4618 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4619 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4620
4621
4622 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4)
4623 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4)
4624 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4)
4625 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4)
4626 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4)
4627 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4)
4628 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4)
4629 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4)
4630
4631
4632 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4)
4633 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4)
4634 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4)
4635 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4)
4636 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4)
4637 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4)
4638 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4)
4639 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4)
4640
4641
4642 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4643 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4644
4645
4646 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4647 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4648
4649
4651 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model.
4652
4653 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4654 """
4655
4656
4657 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded')
4658
4659
4660 spin70 = return_spin(":70")
4661 spin71 = return_spin(":71")
4662
4663
4664 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4665 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4666
4667
4668 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0}
4669 spin70.pA = 0.9
4670 spin70.dw = 6.0
4671 spin70.kex = 1500.0
4672 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0}
4673 spin71.pA = 0.9
4674 spin71.dw = 4.0
4675 spin71.kex = 1900.0
4676
4677
4678 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
4679
4680
4681 print("\n\nOptimised parameters:\n")
4682 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4683 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4684 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4685 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4686 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4687 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4688 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4689
4690
4691 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4)
4692 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4)
4693 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4)
4694 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4)
4695 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4)
4696 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4)
4697
4698
4699 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4)
4700 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4)
4701 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4)
4702 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4)
4703 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4)
4704 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4)
4705
4706
4707 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4708 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4709
4710
4711 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4712 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4713
4714
4716 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model.
4717
4718 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4719 """
4720
4721
4722 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star')
4723
4724
4725 spin70 = return_spin(":70")
4726 spin71 = return_spin(":71")
4727
4728
4729 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4730 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4731
4732
4733 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268}
4734 spin70.pA = 0.9897519798
4735 spin70.dw = 5.644862195
4736 spin70.kex = 1723.820567
4737 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959}
4738 spin71.pA = 0.9968032899
4739 spin71.dw = 4.577891393
4740 spin71.kex = 1830.044597
4741
4742
4743 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1)
4744
4745
4746 print("\n\nOptimised parameters:\n")
4747 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4748 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4749 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4750 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4751 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4752 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4753 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4754
4755
4756 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1)
4757 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1)
4758 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3)
4759 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1)
4760 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1)
4761 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1)
4762
4763
4764 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1)
4765 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2)
4766 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2)
4767 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2)
4768 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1)
4769
4770
4771 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4772 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4773
4774
4775 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4776 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4777
4778
4780 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model.
4781
4782 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period.
4783 """
4784
4785
4786 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full')
4787
4788
4789 spin70 = return_spin(":70")
4790 spin71 = return_spin(":71")
4791
4792
4793 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4794 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4795
4796
4797 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494}
4798 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402}
4799 spin70.pA = 0.987648082613451
4800 spin70.dw = 5.30679853807572
4801 spin70.kex = 2033.25380420666
4802 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435}
4803 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435}
4804 spin71.pA = 0.992258541625787
4805 spin71.dw = 2.75140650899058
4806 spin71.kex = 2106.60885247431
4807
4808
4809 self.interpreter.minimise.calculate()
4810
4811
4812 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2)
4813 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4814
4815
4957
4958
4960 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model.
4961
4962 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
4963
4964 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are:
4965
4966 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887},
4967 - pA = 0.965402506690231,
4968 - dw = 0.805197170133360,
4969 - dwH = -0.595536627771890,
4970 - kex = 569.003663067619868,
4971 - chi2 = 9.297671357952812.
4972 """
4973
4974
4975 self.setup_korzhnev_2005_data(data_list=['DQ'])
4976
4977
4978 spin = return_spin(":9@N")
4979
4980
4981 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6)
4982 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6)
4983 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6)
4984
4985
4986 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344}
4987 spin.pA = 0.965638501551899
4988 spin.dw = 2.8537583461577
4989 spin.dwH = -0.387633062766635
4990 spin.kex = 573.704033851592
4991
4992
4993 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
4994
4995
4996 self.interpreter.monte_carlo.setup(number=2)
4997 self.interpreter.monte_carlo.create_data(method='back_calc')
4998 self.interpreter.monte_carlo.initial_values()
4999 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5000 self.interpreter.monte_carlo.error_analysis()
5001
5002
5003 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5004
5005
5006 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5007
5008
5009 print("\n\nOptimised parameters:\n")
5010 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5011 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5012 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5013 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5014 print("%-20s %20.15g" % ("pA", spin.pA))
5015 print("%-20s %20.15g" % ("dw", spin.dw))
5016 print("%-20s %20.15g" % ("dwH", spin.dwH))
5017 print("%-20s %20.15g" % ("kex", spin.kex))
5018 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5019
5020
5021 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2)
5022 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2)
5023 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2)
5024 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4)
5025 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1)
5026 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2)
5027 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3)
5028 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5029
5030
5032 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model.
5033
5034 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
5035
5036 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are:
5037
5038 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019},
5039 - pA = 0.930027999814003,
5040 - dw = 4.338620619954370,
5041 - dwH = -0.274250775560818,
5042 - kex = 344.613362916544475,
5043 - chi2 = 10.367733168217050.
5044 """
5045
5046
5047 self.setup_korzhnev_2005_data(data_list=['MQ'])
5048
5049
5050 spin = return_spin(":9@N")
5051
5052
5053 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6)
5054 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
5055 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
5056
5057
5058 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622}
5059 spin.pA = 0.930083249288083
5060 spin.dw = 4.33890689462363
5061 spin.dwH = -0.274316585638047
5062 spin.kex = 344.329651956132
5063
5064
5065 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5066
5067
5068 self.interpreter.monte_carlo.setup(number=2)
5069 self.interpreter.monte_carlo.create_data(method='back_calc')
5070 self.interpreter.monte_carlo.initial_values()
5071 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5072 self.interpreter.monte_carlo.error_analysis()
5073
5074
5075 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5076
5077
5078 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5079
5080
5081 print("\n\nOptimised parameters:\n")
5082 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5083 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5084 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5085 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5086 print("%-20s %20.15g" % ("pA", spin.pA))
5087 print("%-20s %20.15g" % ("dw", spin.dw))
5088 print("%-20s %20.15g" % ("dwH", spin.dwH))
5089 print("%-20s %20.15g" % ("kex", spin.kex))
5090 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5091
5092
5093 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1)
5094 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1)
5095 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1)
5096 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3)
5097 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2)
5098 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3)
5099 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3)
5100 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5101
5102
5104 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model.
5105
5106 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
5107
5108 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are:
5109
5110 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822},
5111 - pA = 0.950003458294991,
5112 - dw = 4.358402855315123,
5113 - kex = 429.906473361926999,
5114 - chi2 = 17.393331915567252.
5115 """
5116
5117
5118 self.setup_korzhnev_2005_data(data_list=['SQ'])
5119
5120
5121 spin = return_spin(":9@N")
5122
5123
5124 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
5125 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6)
5126 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
5127
5128
5129 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058}
5130 spin.pA = 0.950310172115387
5131 spin.dw = 4.356737157889636
5132 spin.kex = 433.176323890829849
5133
5134
5135 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5136
5137
5138 self.interpreter.monte_carlo.setup(number=2)
5139 self.interpreter.monte_carlo.create_data(method='back_calc')
5140 self.interpreter.monte_carlo.initial_values()
5141 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5142 self.interpreter.monte_carlo.error_analysis()
5143
5144
5145 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5146
5147
5148 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5149
5150
5151 print("\n\nOptimised parameters:\n")
5152 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5153 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5154 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5155 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5156 print("%-20s %20.15g" % ("pA", spin.pA))
5157 print("%-20s %20.15g" % ("dw", spin.dw))
5158 print("%-20s %20.15g" % ("kex", spin.kex))
5159 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5160
5161
5162 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2)
5163 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2)
5164 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1)
5165 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3)
5166 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2)
5167 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2)
5168 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5169
5170
5172 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model.
5173
5174 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
5175
5176 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are:
5177
5178 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906},
5179 - pA = 0.942452612380140,
5180 - dw = 0.858972784230892,
5181 - dwH = 0.087155962730608,
5182 - kex = 373.219151384798920,
5183 - chi2 = 23.863208106025152.
5184 """
5185
5186
5187 self.setup_korzhnev_2005_data(data_list=['ZQ'])
5188
5189
5190 spin = return_spin(":9@N")
5191
5192
5193 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6)
5194 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6)
5195 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6)
5196
5197
5198 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537}
5199 spin.pA = 0.942457332074014
5200 spin.dw = 0.850592422908884
5201 spin.dwH = 0.0881272284455416
5202 spin.kex = 372.745483351305
5203
5204
5205 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5206
5207
5208 self.interpreter.monte_carlo.setup(number=2)
5209 self.interpreter.monte_carlo.create_data(method='back_calc')
5210 self.interpreter.monte_carlo.initial_values()
5211 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5212 self.interpreter.monte_carlo.error_analysis()
5213
5214
5215 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5216
5217
5218 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5219
5220
5221 print("\n\nOptimised parameters:\n")
5222 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5223 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5224 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5225 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5226 print("%-20s %20.15g" % ("pA", spin.pA))
5227 print("%-20s %20.15g" % ("dw", spin.dw))
5228 print("%-20s %20.15g" % ("dwH", spin.dwH))
5229 print("%-20s %20.15g" % ("kex", spin.kex))
5230 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5231
5232
5233 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2)
5234 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2)
5235 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2)
5236 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4)
5237 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1)
5238 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2)
5239 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3)
5240 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5241
5242
5244 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model.
5245
5246 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
5247
5248 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are:
5249
5250 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728},
5251 - pA = 0.936911090448340,
5252 - dw = 4.325314846914845,
5253 - dwH = -0.213870168665628,
5254 - kex = 487.361914835074117,
5255 - chi2 = 14.870371897291138.
5256 """
5257
5258
5259 self.setup_korzhnev_2005_data(data_list=['1H MQ'])
5260
5261
5262 spin = return_spin(":9@N")
5263
5264
5265 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6)
5266 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6)
5267 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6)
5268
5269
5270 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357}
5271 spin.pA = 0.936884348941701
5272 spin.dw = 4.326454531583964
5273 spin.dwH = -0.214026093221782
5274 spin.kex = 487.043592705469223
5275
5276
5277 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100)
5278
5279
5280 self.interpreter.monte_carlo.setup(number=2)
5281 self.interpreter.monte_carlo.create_data(method='back_calc')
5282 self.interpreter.monte_carlo.initial_values()
5283 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5284 self.interpreter.monte_carlo.error_analysis()
5285
5286
5287 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5288
5289
5290 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5291
5292
5293 print("\n\nOptimised parameters:\n")
5294 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5295 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5296 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5297 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5298 print("%-20s %20.15g" % ("pA", spin.pA))
5299 print("%-20s %20.15g" % ("dw", spin.dw))
5300 print("%-20s %20.15g" % ("dwH", spin.dwH))
5301 print("%-20s %20.15g" % ("kex", spin.kex))
5302 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5303
5304
5305 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4)
5306 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2)
5307 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2)
5308 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4)
5309 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2)
5310 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2)
5311 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4)
5312 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5313
5314
5316 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model.
5317
5318 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
5319
5320 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are:
5321
5322 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072},
5323 - pA = 0.946949480545876,
5324 - dwH = -0.265279672133308,
5325 - kex = 406.548178869750700,
5326 - chi2 = 50.400680290545026.
5327 """
5328
5329
5330 self.setup_korzhnev_2005_data(data_list=['1H SQ'])
5331
5332
5333 spin = return_spin(":9@N")
5334
5335
5336 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6)
5337 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6)
5338 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6)
5339
5340
5341 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077}
5342 spin.pA = 0.946990967372467
5343 spin.dwH = -0.265308128403529
5344 spin.kex = 406.843250675648
5345
5346
5347 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5348
5349
5350 self.interpreter.monte_carlo.setup(number=2)
5351 self.interpreter.monte_carlo.create_data(method='back_calc')
5352 self.interpreter.monte_carlo.initial_values()
5353 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5354 self.interpreter.monte_carlo.error_analysis()
5355
5356
5357 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5358
5359
5360 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5361
5362
5363 print("\n\nOptimised parameters:\n")
5364 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5365 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5366 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5367 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5368 print("%-20s %20.15g" % ("pA", spin.pA))
5369 print("%-20s %20.15g" % ("dwH", spin.dwH))
5370 print("%-20s %20.15g" % ("kex", spin.kex))
5371 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5372
5373
5374 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2)
5375 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2)
5376 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2)
5377 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4)
5378 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3)
5379 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2)
5380 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5381
5382
5384 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model.
5385
5386 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
5387
5388 Here all data will be optimised. The values found by cpmg_fit using just this data are:
5389
5390 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596,
5391 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709,
5392 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030,
5393 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627,
5394 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979,
5395 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118},
5396 - pA = 0.943125351763911,
5397 - dw = 4.421827493809807,
5398 - dwH = -0.272637034755752,
5399 - kex = 360.609744568697238,
5400 - chi2 = 162.589570340050813.
5401 """
5402
5403
5404 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ'])
5405
5406
5407 spin = return_spin(":9@N")
5408
5409
5410 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6)
5411 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6)
5412 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6)
5413 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
5414 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6)
5415 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
5416 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6)
5417 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6)
5418 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6)
5419 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6)
5420 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6)
5421 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6)
5422 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6)
5423 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6)
5424 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6)
5425 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6)
5426 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
5427 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
5428
5429
5430 spin.r2 = {
5431 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704,
5432 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930,
5433 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265,
5434 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090,
5435 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380,
5436 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750
5437 }
5438 spin.pA = 0.943129019477673
5439 spin.dw = 4.42209952545181
5440 spin.dwH = -0.27258970590969
5441 spin.kex = 360.516132791038
5442
5443
5444 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10)
5445
5446
5447 self.interpreter.monte_carlo.setup(number=2)
5448 self.interpreter.monte_carlo.create_data(method='back_calc')
5449 self.interpreter.monte_carlo.initial_values()
5450 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5451 self.interpreter.monte_carlo.error_analysis()
5452
5453
5454 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5455
5456
5457 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5458
5459
5460 print("\n\nOptimised parameters:\n")
5461 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5462 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1]))
5463 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2]))
5464 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3]))
5465 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4]))
5466 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5]))
5467 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6]))
5468 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7]))
5469 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8]))
5470 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9]))
5471 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10]))
5472 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11]))
5473 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12]))
5474 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13]))
5475 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14]))
5476 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15]))
5477 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16]))
5478 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17]))
5479 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18]))
5480 print("%-20s %20.15g" % ("pA", spin.pA))
5481 print("%-20s %20.15g" % ("dw", spin.dw))
5482 print("%-20s %20.15g" % ("dwH", spin.dwH))
5483 print("%-20s %20.15g" % ("kex", spin.kex))
5484 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5485
5486
5487 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4)
5488 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4)
5489 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4)
5490 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4)
5491 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4)
5492 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4)
5493 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4)
5494 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4)
5495 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4)
5496 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4)
5497 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4)
5498 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4)
5499 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4)
5500 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4)
5501 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4)
5502 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4)
5503 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4)
5504 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4)
5505 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4)
5506 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4)
5507 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4)
5508 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4)
5509 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5510
5511
5513 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model.
5514
5515 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant.
5516
5517 Here all data will be optimised. The values found by cpmg_fit using just this data are:
5518
5519 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596,
5520 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709,
5521 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030,
5522 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627,
5523 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979,
5524 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118},
5525 - pA = 0.943125351763911,
5526 - dw = 4.421827493809807,
5527 - dwH = -0.272637034755752,
5528 - kex = 360.609744568697238,
5529 - chi2 = 162.589570340050813.
5530 """
5531
5532
5533 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ'])
5534
5535
5536 spin = return_spin(":9@N")
5537
5538
5539 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6)
5540 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6)
5541 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6)
5542 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
5543 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6)
5544 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
5545 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6)
5546 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6)
5547 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6)
5548 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6)
5549 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6)
5550 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6)
5551 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6)
5552 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6)
5553 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6)
5554 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6)
5555 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
5556 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
5557
5558
5559 spin.r2 = {
5560 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704,
5561 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930,
5562 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265,
5563 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090,
5564 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380,
5565 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750
5566 }
5567 spin.pA = 0.943129019477673
5568 spin.dw = 4.42209952545181
5569 spin.dwH = -0.27258970590969
5570 spin.kex = 360.516132791038
5571
5572
5573 self.interpreter.minimise.calculate(verbosity=1)
5574
5575
5576 print("\n\nOptimised parameters:\n")
5577 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5578 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1]))
5579 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2]))
5580 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3]))
5581 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4]))
5582 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5]))
5583 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6]))
5584 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7]))
5585 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8]))
5586 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9]))
5587 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10]))
5588 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11]))
5589 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12]))
5590 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13]))
5591 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14]))
5592 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15]))
5593 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16]))
5594 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17]))
5595 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18]))
5596 print("%-20s %20.15g" % ("pA", spin.pA))
5597 print("%-20s %20.15g" % ("dw", spin.dw))
5598 print("%-20s %20.15g" % ("dwH", spin.dwH))
5599 print("%-20s %20.15g" % ("kex", spin.kex))
5600 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5601
5602
5603 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5604
5605
5607 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5608
5609 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride).
5610
5611 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are:
5612
5613 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1]
5614 - 0.483 0.89623903 2.4503699912708878
5615 - 0.545 1.1694838
5616 - 0.545 1.1761503
5617 - 0.622 1.294
5618 - 0.669 1.5176493
5619 - 0.722 1.6238791
5620 - 0.813 1.9395758
5621 - 1.011 2.3558415 10.547000429321157
5622 """
5623
5624
5625 model = 'TSMFK01'
5626 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223"
5627 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder)
5628
5629
5630 res61L = cdp.mol[0].res[0].spin[0]
5631
5632
5633 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
5634
5635
5636 res61L.r2a = {r20_key1: 8.0}
5637 res61L.dw = 6.5
5638 res61L.k_AB = 2.5
5639
5640
5641 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
5642
5643
5644 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO]
5645 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF]
5646 interpolate_types = [INTERPOLATE_DISP]
5647
5648
5649 result_dir_name = ds.tmpdir
5650 result_folders = [model]
5651 spin_id = ":61@N"
5652
5653
5654 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs'
5655
5656 for result_folder in result_folders:
5657 for y_axis in y_axis_types:
5658 for x_axis in x_axis_types:
5659 for interpolate in interpolate_types:
5660
5661 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate)
5662
5663
5664 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
5665
5666
5667 dir = result_dir_name+sep+result_folder
5668 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate))
5669 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True)
5670
5671
5672 file_path = get_file_path(file_name, dir)
5673
5674
5675 print("Testing file access to graph: %s"%file_path)
5676 self.assert_(access(file_path, F_OK))
5677
5678
5679 file_prod = open(file_path)
5680 lines_prod = file_prod.readlines()
5681 file_prod.close()
5682
5683
5684 dir_comp = data_path+sep+result_folder
5685 file_path_comp = get_file_path(file_name, dir_comp)
5686 file_comp = open(file_path_comp)
5687 lines_comp = file_comp.readlines()
5688 file_comp.close()
5689
5690
5691 self.assertEqual(len(lines_prod), len(lines_comp))
5692 for j in range(len(lines_prod)):
5693
5694 first_char = lines_prod[j][0]
5695 if first_char in ["@", "&"]:
5696 self.assertEqual(lines_prod[j], lines_comp[j])
5697 else:
5698
5699
5700 x_prod, y_prod, y_prod_err = lines_prod[j].split()
5701 x_comp, y_comp, y_comp_err = lines_comp[j].split()
5702 self.assertAlmostEqual(float(x_prod), float(x_comp))
5703 self.assertAlmostEqual(float(y_prod), float(y_comp))
5704 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5705
5706
5708 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5709
5710 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride).
5711 """
5712
5713
5714 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223")
5715
5716
5717 res61L = cdp.mol[0].res[0].spin[0]
5718
5719
5720 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
5721
5722
5723 res61L.r2 = {r20_key1: 8.0}
5724 res61L.pA = 0.9
5725 res61L.dw = 6.0
5726 res61L.kex = 600.0
5727
5728
5729 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
5730
5731
5732 print("\n\nOptimised parameters:\n")
5733 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
5734 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1]))
5735 print("%-20s %20.15g" % ("pA", res61L.pA))
5736 print("%-20s %20.15g" % ("dw", res61L.dw))
5737 print("%-20s %20.15g" % ("kex", res61L.kex))
5738 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
5739
5740
5741 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4)
5742 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5)
5743 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3)
5744 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0)
5745 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5)
5746
5747
5748 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA))
5749
5750
5751 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5752
5753
5755 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5756
5757 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride).
5758 """
5759
5760
5761 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223")
5762
5763
5764 res61L = cdp.mol[0].res[0].spin[0]
5765
5766
5767 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
5768
5769
5770 res61L.r2a = {r20_key1: 8.0}
5771 res61L.r2b = {r20_key1: 105.0}
5772 res61L.pA = 0.9
5773 res61L.dw = 6.0
5774 res61L.kex = 500.0
5775
5776
5777 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
5778
5779
5780 print("\n\nOptimised parameters:\n")
5781 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
5782 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1]))
5783 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1]))
5784 print("%-20s %20.15g" % ("pA", res61L.pA))
5785 print("%-20s %20.15g" % ("dw", res61L.dw))
5786 print("%-20s %20.15g" % ("kex", res61L.kex))
5787 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
5788
5789
5790 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0)
5791 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2)
5792 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2)
5793 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3)
5794 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2)
5795 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5796
5797
5799 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5800
5801 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride).
5802
5803 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are:
5804
5805 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1]
5806 - 0.483 0.89623903 2.4503699912708878
5807 - 0.545 1.1694838
5808 - 0.545 1.1761503
5809 - 0.622 1.294
5810 - 0.669 1.5176493
5811 - 0.722 1.6238791
5812 - 0.813 1.9395758
5813 - 1.011 2.3558415 10.547000429321157
5814 """
5815
5816
5817 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223")
5818
5819
5820 res61L = cdp.mol[0].res[0].spin[0]
5821
5822
5823 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
5824
5825
5826 res61L.r2a = {r20_key1: 8.0}
5827 res61L.dw = 6.5
5828 res61L.k_AB = 2.5
5829
5830
5831 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
5832
5833
5834 print("\n\nOptimised parameters:\n")
5835 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
5836 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1]))
5837 print("%-20s %20.15g" % ("dw", res61L.dw))
5838 print("%-20s %20.15g" % ("k_AB", res61L.k_AB))
5839 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
5840
5841
5842
5843 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5844
5845
5847 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5848
5849 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride).
5850
5851 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably.
5852
5853 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C:
5854
5855 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1:
5856 - k_AB = 11.3 +/- 0.7 s^-1,
5857 - dw = (2.45 +/- 0.09) * 10^3 s^-1,
5858 - R2 = 8.0 +/- 0.5 s^-1.
5859
5860 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.:
5861 - k_AB = 10.55 +/- 0.08 s^-1,
5862 - dw = (2.44 +/- 0.08) * 10^3 s^-1,
5863 - R2 = 8.4 +/- 0.3 s^-1.
5864
5865 Conversion of paper results to relax results is performed by:
5866
5867 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm.
5868
5869 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are:
5870
5871 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1]
5872 - 0.483 0.89623903 2.4503699912708878
5873 - 0.545 1.1694838
5874 - 0.545 1.1761503
5875 - 0.622 1.294
5876 - 0.669 1.5176493
5877 - 0.722 1.6238791
5878 - 0.813 1.9395758
5879 - 1.011 2.3558415 10.547000429321157
5880 """
5881
5882
5883 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223")
5884
5885
5886 res61L = cdp.mol[0].res[0].spin[0]
5887
5888
5889 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6)
5890
5891
5892 res61L.r2a = {r20_key1: 8.0}
5893 res61L.dw = 6.5
5894 res61L.k_AB = 11.0
5895
5896
5897 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
5898
5899
5900 print("\n\nOptimised parameters:\n")
5901 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
5902 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1]))
5903 print("%-20s %20.15g" % ("dw", res61L.dw))
5904 print("%-20s %20.15g" % ("k_AB", res61L.k_AB))
5905 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
5906
5907
5908
5909 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0)
5910 self.assertAlmostEqual(res61L.dw, 6.41, 0)
5911 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
5912
5913
5915 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data."""
5916
5917
5918 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site'
5919
5920
5921 self.interpreter.reset()
5922 self.interpreter.state.load(data_path+sep+'r2eff_values')
5923
5924
5925 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp')
5926 self.interpreter.pipe.switch(pipe_name='LM63 3-site')
5927
5928
5929 self.interpreter.relax_disp.select_model(model='LM63 3-site')
5930 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff')
5931 self.interpreter.spin.isotope('15N')
5932
5933
5934 spin1 = return_spin(":1")
5935 spin2 = return_spin(":2")
5936
5937
5938 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
5939 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
5940
5941
5942 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0}
5943 spin1.phi_ex_B = 0.1
5944 spin1.phi_ex_C = 0.5
5945 spin1.kB = 1500.0
5946 spin1.kC = 2500.0
5947 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0}
5948 spin2.phi_ex_B = 0.1
5949 spin2.phi_ex_C = 0.5
5950 spin2.kB = 1500.0
5951 spin2.kC = 2500.0
5952
5953
5954 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1)
5955
5956
5957 self.interpreter.monte_carlo.setup(number=3)
5958 self.interpreter.monte_carlo.create_data(method='back_calc')
5959 self.interpreter.monte_carlo.initial_values()
5960 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1)
5961 self.interpreter.monte_carlo.error_analysis()
5962
5963
5964 self.interpreter.results.write(file='devnull', compress_type=1, force=True)
5965
5966
5967 print("\n\nOptimised parameters:\n")
5968 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
5969 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
5970 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
5971 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B))
5972 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C))
5973 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB))
5974 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC))
5975 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
5976 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2)
5977 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2)
5978 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3)
5979 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3)
5980 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3)
5981 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3)
5982 self.assertAlmostEqual(spin1.chi2, 0.0, 3)
5983 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3)
5984 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3)
5985 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3)
5986 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3)
5987 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3)
5988 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3)
5989 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
5990
5991
5993 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data."""
5994
5995
5996 ds.fixed = True
5997
5998
5999 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py')
6000
6001
6002 i0 = [100000.0, 20000.0]
6003 r1rho_prime = [2.25, 24.0]
6004 pA = 0.7
6005 kex = 1000.0
6006 delta_omega = [1.0, 2.0]
6007 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000']
6008 phi_ex = []
6009 for i in range(2):
6010 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2)
6011 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]]
6012
6013
6014 self.interpreter.pipe.switch('R2eff - relax_disp')
6015 spin_index = 0
6016 for spin, spin_id in spin_loop(return_id=True):
6017
6018 print("\nSpin %s." % spin_id)
6019
6020
6021 for i in range(len(keys)):
6022 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2)
6023
6024
6025 spin_index += 1
6026
6027
6028 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
6029
6030
6031 self.interpreter.pipe.switch('M61 - relax_disp')
6032 spin_index = 0
6033 for spin, spin_id in spin_loop(return_id=True):
6034
6035 print("\nSpin %s." % spin_id)
6036
6037
6038 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2)
6039 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2)
6040 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
6041
6042
6043 spin_index += 1
6044
6045
6047 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data."""
6048
6049
6050 ds.fixed = False
6051
6052
6053 ds.single = True
6054
6055
6056 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py')
6057
6058
6059 i0 = [100000.0, 20000.0]
6060 r1rho_prime = [2.25, 24.0]
6061 pA = 0.7
6062 kex = 1000.0
6063 delta_omega = [1.0, 2.0]
6064 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000']
6065 phi_ex = []
6066 for i in range(2):
6067 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2)
6068 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]]
6069
6070
6071 self.interpreter.pipe.switch('R2eff - relax_disp')
6072 spin_index = 0
6073 for spin, spin_id in spin_loop(return_id=True):
6074
6075 print("\nSpin %s." % spin_id)
6076
6077
6078 for i in range(len(keys)):
6079 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2)
6080
6081
6082 spin_index += 1
6083
6084
6085 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
6086
6087
6088 self.interpreter.pipe.switch('M61 - relax_disp')
6089 spin_index = 0
6090 for spin, spin_id in spin_loop(return_id=True):
6091
6092 print("\nSpin %s." % spin_id)
6093
6094
6095 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2)
6096 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2)
6097 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
6098
6099
6100 spin_index += 1
6101
6102
6104 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data."""
6105
6106
6107 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py')
6108
6109
6110 i0 = [100000.0, 20000.0]
6111 r1rho_prime = [10.0, 24.0]
6112 pA = 0.95
6113 kex = 2000.0
6114 delta_omega = [1.0, 2.0]
6115
6116
6117 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
6118
6119
6120 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B)
6121 spin_index = 0
6122 for spin, spin_id in spin_loop(return_id=True):
6123
6124 print("\nSpin %s." % spin_id)
6125
6126
6127 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2)
6128 self.assertAlmostEqual(spin.pA, pA, 2)
6129 self.assertAlmostEqual(spin.dw, dw[spin_index], 2)
6130 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
6131
6132
6133 spin_index += 1
6134
6135
6137 """Test that all models which can nest, have all their parameters converted."""
6138
6139
6140 cdp.exp_type_list = EXP_TYPE_LIST
6141
6142
6143 all_models_info = models_info(models=MODEL_LIST_FULL)
6144
6145
6146 print("Printing the listed of nested models for each model.")
6147 print("#########################################")
6148 for model_info in all_models_info:
6149 print("%s"%model_info.model),
6150 print("<-"),
6151 nest_list = model_info.nest_list
6152 if nest_list == None:
6153 nest_list = ["None"]
6154 print(', '.join(map(str, nest_list)))
6155
6156
6157 if nest_list == ["None"]:
6158 continue
6159
6160
6161 model_params = model_info.params
6162
6163
6164 for nested_model in nest_list:
6165
6166 nested_model_params = MODEL_PARAMS[nested_model]
6167
6168
6169 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params)
6170
6171
6172 self.assertEqual(len(par_dic), len(model_params))
6173
6174
6175 for param in par_dic:
6176 if param != par_dic[param]:
6177 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param))
6178 self.assertNotEqual(par_dic[param], None)
6179
6180
6182 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit."""
6183
6184
6185 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py')
6186
6187
6188 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6189
6190
6192 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit."""
6193
6194
6195 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py')
6196
6197
6198 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6199
6200
6202 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit."""
6203
6204
6205 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py')
6206
6207
6208 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6209
6210
6212 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit."""
6213
6214
6215 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py')
6216
6217
6218 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6219
6220
6222 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg.
6223
6224 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data.
6225 """
6226
6227
6228 self.interpreter.reset()
6229
6230
6231 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'
6232
6233
6234 sdic = {}
6235
6236
6237 sfrq_1 = 499.86214
6238 sfrq_2 = 599.8908587
6239 sfrqs = [sfrq_1, sfrq_2]
6240
6241
6242 sdic['sfrqs'] = sfrqs
6243
6244
6245 sdic['sfrq_unit'] = 'MHz'
6246
6247
6248 sdic['exp_type'] = 'SQ CPMG'
6249
6250
6251 sdic['isotope'] = '15N'
6252
6253
6254 sdic['int_method'] = 'height'
6255
6256
6257 sdic['time'] = '2014_09'
6258
6259
6260 for frq in sfrqs:
6261 key = DIC_KEY_FORMAT % (frq)
6262 sdic[key] = {}
6263
6264
6265 e_1 = DIC_KEY_FORMAT % (sfrq_1)
6266 e_2 = DIC_KEY_FORMAT % (sfrq_2)
6267
6268
6269 sdic[e_1]['time_T2'] = 0.04
6270 sdic[e_2]['time_T2'] = 0.06
6271
6272
6273 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0])
6274 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22])
6275
6276
6277 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2']
6278 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2']
6279
6280
6281 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files'
6282 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files'
6283 sdic[e_1]['peaks_folder'] = peaks_folder_1
6284 sdic[e_2]['peaks_folder'] = peaks_folder_2
6285
6286
6287 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data'
6288 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data'
6289 sdic[e_1]['rmsd_folder'] = rmsd_folder_1
6290 sdic[e_2]['rmsd_folder'] = rmsd_folder_2
6291
6292
6293 sdic['results_dir'] = self.tmpdir
6294
6295
6296 RDR = Relax_disp_rep(sdic)
6297
6298
6299 RDR.set_base_cpmg(method='FT', glob_ini=128)
6300
6301 methods = ['FT', 'MDD']
6302
6303
6304
6305
6306
6307
6308
6309 if True:
6310 selection = None
6311
6312
6313 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection)
6314
6315
6316 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection)
6317
6318
6319 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]]
6320 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]]
6321 corr_data = [fig1, fig2]
6322
6323 write_stats = True
6324 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats)
6325
6326
6327 if write_stats:
6328 for i, corr_data_i in enumerate(corr_data):
6329 data, methods, glob_inis = corr_data[i]
6330 data_x, data_y = data
6331 method_x, method_y = methods
6332 glob_ini_x, glob_ini_y = glob_inis
6333 x = data_x[str(glob_ini_x)]['peak_intensity_arr']
6334 np = len(x)
6335
6336 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np)
6337
6338 if selection == None:
6339 file_name = file_name_ini + '_all.txt'
6340 else:
6341 file_name = file_name_ini + '_sel.txt'
6342 path = RDR.results_dir
6343 data = extract_data(file=file_name, dir=path)
6344
6345
6346 for i, data_i in enumerate(data):
6347 print(i, data_i)
6348
6349
6350
6351 if True:
6352
6353 selections = [None, ':2,3']
6354 for selection in selections:
6355 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection)
6356 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection)
6357
6358
6359 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126])
6360
6361
6362 write_stats = True
6363 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats)
6364
6365
6366 if write_stats:
6367 if selection == None:
6368 file_name = 'int_stat_all.txt'
6369 else:
6370 file_name = 'int_stat_sel.txt'
6371 path = RDR.results_dir
6372 data = extract_data(file=file_name, dir=path)
6373
6374
6375 for i, data_i in enumerate(data):
6376 print(i, data_i)
6377
6378
6379
6380 if True:
6381 selection = None
6382
6383 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection)
6384
6385
6386 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection)
6387
6388
6389 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]]
6390 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]]
6391 corr_data = [fig1, fig2]
6392
6393 write_stats = True
6394 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats)
6395
6396
6397 if write_stats:
6398 for i, corr_data_i in enumerate(corr_data):
6399 data, methods, glob_inis = corr_data[i]
6400 data_x, data_y = data
6401 method_x, method_y = methods
6402 glob_ini_x, glob_ini_y = glob_inis
6403 x = data_x[str(glob_ini_x)]['r2eff_arr']
6404 np = len(x)
6405
6406 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np)
6407
6408 if selection == None:
6409 file_name = file_name_ini + '_all.txt'
6410 else:
6411 file_name = file_name_ini + '_sel.txt'
6412 path = RDR.results_dir
6413 data = extract_data(file=file_name, dir=path)
6414
6415
6416 for i, data_i in enumerate(data):
6417 print(i, data_i)
6418
6419
6420
6421 if True:
6422
6423 selections = [None, ':2,3']
6424 for selection in selections:
6425 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection)
6426 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection)
6427
6428
6429 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126])
6430
6431
6432 write_stats = True
6433 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats)
6434
6435
6436 if write_stats:
6437 if selection == None:
6438 file_name = 'r2eff_stat_all.txt'
6439 else:
6440 file_name = 'r2eff_stat_sel.txt'
6441 path = RDR.results_dir
6442 data = extract_data(file=file_name, dir=path)
6443
6444
6445 for i, data_i in enumerate(data):
6446 print(i, data_i)
6447
6448
6449
6450 if True:
6451 methods = ['FT', 'MDD']
6452
6453 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126])
6454
6455 min_methods = [['FT'], ['MDD']]
6456 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]]
6457
6458
6459
6460
6461 selection = None
6462
6463 for i, methods in enumerate(min_methods):
6464 list_glob_ini = min_list_glob_ini[i]
6465
6466 if True:
6467
6468 if True:
6469
6470 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini)
6471
6472
6473 if True:
6474
6475 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True)
6476
6477
6478 if True:
6479
6480 method = methods[0]
6481 glob_ini = list_glob_ini[0]
6482
6483 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini)
6484 RDR.spin_display_params(pipe_name=test_pipe_name)
6485
6486
6487 if True:
6488
6489 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True)
6490
6491
6492 if True:
6493
6494 RDR.opt_max_iterations = int(1e2)
6495 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True)
6496
6497
6498
6499
6500
6501 if True:
6502 selections = [None, ':2,3']
6503 for selection in selections:
6504
6505 analysis = 'min_ind'
6506 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
6507 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
6508
6509 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]]
6510 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]]
6511 corr_data = [fig1, fig2]
6512
6513 write_stats = True
6514 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats)
6515
6516
6517 if write_stats:
6518 for i, corr_data_i in enumerate(corr_data):
6519 data, methods, glob_inis = corr_data[i]
6520 data_x, data_y = data
6521 method_x, method_y = methods
6522 glob_ini_x, glob_ini_y = glob_inis
6523
6524 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y)
6525
6526 if selection == None:
6527 file_name = file_name_ini + '_all.txt'
6528 else:
6529 file_name = file_name_ini + '_sel.txt'
6530 path = RDR.results_dir
6531 data = extract_data(file=file_name, dir=path)
6532
6533
6534 for i, data_i in enumerate(data):
6535 print(i, data_i)
6536
6537
6538 if True:
6539
6540
6541 selections = [None, ':2,3']
6542 for selection in selections:
6543 analysis = 'min_ind'
6544 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
6545 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
6546
6547
6548 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126])
6549
6550
6551 write_stats = True
6552 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats)
6553
6554
6555 if write_stats:
6556 if selection == None:
6557 file_name = '%s_stat_all.txt' % (analysis)
6558 else:
6559 file_name = '%s_stat_sel.txt' % (analysis)
6560 path = RDR.results_dir
6561 data = extract_data(file=file_name, dir=path)
6562
6563
6564 for i, data_i in enumerate(data):
6565 print(i, data_i)
6566
6567
6568
6569 if True:
6570 methods = ['FT', 'MDD']
6571
6572 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126])
6573
6574 min_methods = [['FT'], ['MDD']]
6575 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]]
6576
6577
6578
6579 selection = ':2,3'
6580
6581 for i, methods in enumerate(min_methods):
6582 list_glob_ini = min_list_glob_ini[i]
6583
6584 if True:
6585
6586 if True:
6587
6588 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini)
6589
6590
6591 if True:
6592
6593 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True)
6594
6595 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True)
6596
6597
6598 if True:
6599
6600 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True)
6601 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True)
6602
6603
6604 if True:
6605
6606 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True)
6607
6608
6609 if True:
6610
6611 method = methods[0]
6612 glob_ini = list_glob_ini[0]
6613
6614 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini)
6615 RDR.spin_display_params(pipe_name=test_pipe_name)
6616
6617
6618 if True:
6619
6620 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True)
6621
6622
6623 if True:
6624 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True)
6625
6626
6627 if True:
6628
6629 RDR.opt_max_iterations = int(1e2)
6630 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False)
6631
6632
6633
6634 if True:
6635 selection = ':2,3'
6636
6637 analysis = 'min'
6638 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
6639 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
6640
6641 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]]
6642 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]]
6643 corr_data = [fig1, fig2]
6644
6645 write_stats = True
6646 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats)
6647
6648
6649 if write_stats:
6650 for i, corr_data_i in enumerate(corr_data):
6651 data, methods, glob_inis = corr_data[i]
6652 data_x, data_y = data
6653 method_x, method_y = methods
6654 glob_ini_x, glob_ini_y = glob_inis
6655
6656 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y)
6657
6658 if selection == None:
6659 file_name = file_name_ini + '_all.txt'
6660 else:
6661 file_name = file_name_ini + '_sel.txt'
6662 path = RDR.results_dir
6663 data = extract_data(file=file_name, dir=path)
6664
6665
6666 for i, data_i in enumerate(data):
6667 print(i, data_i)
6668
6669
6670 if True:
6671
6672 selections = [':2,3']
6673 for selection in selections:
6674 analysis = 'min'
6675 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
6676 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
6677
6678
6679 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126])
6680
6681
6682 write_stats = True
6683 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats)
6684
6685
6686 if write_stats:
6687 if selection == None:
6688 file_name = '%s_stat_all.txt' % (analysis)
6689 else:
6690 file_name = '%s_stat_sel.txt' % (analysis)
6691 path = RDR.results_dir
6692 data = extract_data(file=file_name, dir=path)
6693
6694
6695 for i, data_i in enumerate(data):
6696 print(i, data_i)
6697
6698
6699
6701 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
6702
6703 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
6704
6705 This uses the automatic analysis.
6706
6707 """
6708
6709
6710 cluster_ids = [
6711 ":13@N",
6712 ":15@N",
6713 ":16@N",
6714 ":25@N",
6715 ":26@N",
6716 ":28@N",
6717 ":39@N",
6718 ":40@N",
6719 ":41@N",
6720 ":43@N",
6721 ":44@N",
6722 ":45@N",
6723 ":49@N",
6724 ":52@N",
6725 ":53@N"]
6726
6727
6728 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids)
6729
6730
6731 self.assertEqual(len(cdp.mol), 1)
6732 self.assertEqual(cdp.mol[0].name, None)
6733 self.assertEqual(len(cdp.mol[0].res), 48)
6734
6735
6736 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393,
6737 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279,
6738 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160,
6739 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048]
6740
6741 i = 0
6742 for spin, spin_id in spin_loop(return_id=True):
6743
6744 self.assertEqual(spin.chemical_shift, cs[i])
6745
6746
6747 i += 1
6748
6749
6750 i = 0
6751 j = 0
6752
6753 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
6754 if curspin.select == True:
6755 i += 1
6756 if curspin.select == False:
6757 j += 1
6758
6759
6760 self.assertEqual(i, len(cluster_ids))
6761 self.assertEqual(j, 48-len(cluster_ids))
6762
6763
6764 self.assertEqual(cdp.mol[0].res[7].num, 13)
6765 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6])
6766 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2])
6767
6768 self.assertEqual(cdp.mol[0].res[9].num, 15)
6769 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6])
6770 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2])
6771
6772 self.assertEqual(cdp.mol[0].res[10].num, 16)
6773 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6])
6774 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data'))
6775
6776 self.assertEqual(cdp.mol[0].res[16].num, 25)
6777 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6])
6778 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data'))
6779
6780 self.assertEqual(cdp.mol[0].res[17].num, 26)
6781 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6])
6782 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data'))
6783
6784 self.assertEqual(cdp.mol[0].res[19].num, 28)
6785 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6])
6786 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data'))
6787
6788 self.assertEqual(cdp.mol[0].res[29].num, 39)
6789 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6])
6790 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data'))
6791
6792 self.assertEqual(cdp.mol[0].res[30].num, 40)
6793 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6])
6794 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data'))
6795
6796 self.assertEqual(cdp.mol[0].res[31].num, 41)
6797 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6])
6798 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data'))
6799
6800 self.assertEqual(cdp.mol[0].res[33].num, 43)
6801 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6])
6802 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data'))
6803
6804 self.assertEqual(cdp.mol[0].res[34].num, 44)
6805 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6])
6806 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data'))
6807
6808 self.assertEqual(cdp.mol[0].res[35].num, 45)
6809 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6])
6810 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data'))
6811
6812 self.assertEqual(cdp.mol[0].res[38].num, 49)
6813 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6])
6814 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data'))
6815
6816 self.assertEqual(cdp.mol[0].res[41].num, 52)
6817 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6])
6818 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data'))
6819
6820 self.assertEqual(cdp.mol[0].res[42].num, 53)
6821 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6])
6822 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data'))
6823
6824
6825 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
6826
6827
6828 GRID_INC = 4
6829
6830
6831 MC_NUM = 3
6832
6833
6834 MODSEL = 'AIC'
6835
6836
6837
6838 OPT_FUNC_TOL = 1e-1
6839 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
6840 OPT_MAX_ITERATIONS = 1000
6841 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
6842
6843 result_dir_name = ds.tmpdir
6844
6845
6846 for curspin in cluster_ids:
6847 self.interpreter.relax_disp.cluster('free spins', curspin)
6848
6849 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
6850
6851
6852
6853
6854
6855
6856
6857
6858 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
6859
6860
6861
6862 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL)
6863
6864
6865
6866
6867
6868 print("\n\n################")
6869 print("Printing results")
6870 print("################\n")
6871 for model in MODELS:
6872
6873 if model == MODEL_R2EFF:
6874 continue
6875
6876
6877 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model))
6878 print("\nModel: %s" % (model))
6879
6880
6881 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
6882
6883 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
6884
6885
6886 print("Optimised parameters for spin: %s" % (spin_string))
6887 for param in cur_spin.params + ['chi2']:
6888
6889 if param in ['r1', 'r2']:
6890 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True):
6891
6892 r20_key = generate_r20_key(exp_type=exp_type, frq=frq)
6893
6894
6895 value = getattr(cur_spin, param)[r20_key]
6896
6897
6898 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value))
6899
6900
6901 else:
6902
6903 value = getattr(cur_spin, param)
6904
6905
6906 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value))
6907
6908
6909 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final'))
6910 print("\nFinal pipe")
6911
6912
6914 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model.
6915
6916 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
6917
6918 This uses the automatic analysis.
6919
6920 """
6921
6922
6923 cluster_ids = [
6924 ":52@N"]
6925
6926
6927 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids)
6928
6929
6930 MODELS = [MODEL_R2EFF]
6931
6932
6933 GRID_INC = 4
6934
6935
6936 MC_NUM = 3
6937
6938
6939 MODSEL = 'AIC'
6940
6941
6942
6943 OPT_FUNC_TOL = 1e-1
6944 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
6945 OPT_MAX_ITERATIONS = 1000
6946 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
6947
6948 result_dir_name = ds.tmpdir
6949
6950
6951 for curspin in cluster_ids:
6952 self.interpreter.relax_disp.cluster('free spins', curspin)
6953
6954 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
6955
6956 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
6957
6958
6959 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL)
6960
6961
6962 graph_comb = [
6963 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP],
6964 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP],
6965 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP],
6966 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET]
6967 ]
6968
6969
6970 result_folders = MODELS
6971
6972
6973 spin_id = ':52@N'
6974
6975
6976 for result_folder in result_folders:
6977
6978 if result_folder == MODEL_R2EFF:
6979 continue
6980
6981
6982 for y_axis, x_axis, interpolate in graph_comb:
6983
6984 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate)
6985
6986
6987 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
6988
6989
6990 file_path = get_file_path(file_name, result_dir_name+sep+result_folder)
6991
6992 print("Testing file access to graph: %s"%file_path)
6993 self.assert_(access(file_path, F_OK))
6994
6995
6996 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO]
6997 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF]
6998 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET]
6999
7000 result_dir_name = ds.tmpdir
7001
7002
7003 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs'
7004
7005 for result_folder in result_folders:
7006
7007 if result_folder == MODEL_R2EFF:
7008 continue
7009
7010 for y_axis in y_axis_types:
7011 for x_axis in x_axis_types:
7012 for interpolate in interpolate_types:
7013
7014 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate)
7015
7016
7017 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
7018
7019
7020 dir = result_dir_name+sep+result_folder
7021 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate))
7022 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True)
7023
7024
7025 file_path = get_file_path(file_name, dir)
7026
7027
7028 print("Testing file access to graph: %s"%file_path)
7029 self.assert_(access(file_path, F_OK))
7030
7031
7032 file_prod = open(file_path)
7033 lines_prod = file_prod.readlines()
7034 file_prod.close()
7035
7036
7037 dir_comp = data_path+sep+result_folder
7038 file_path_comp = get_file_path(file_name, dir_comp)
7039 file_comp = open(file_path_comp)
7040 lines_comp = file_comp.readlines()
7041 file_comp.close()
7042
7043
7044 self.assertEqual(len(lines_prod), len(lines_comp))
7045 for j in range(len(lines_prod)):
7046
7047 first_char = lines_prod[j][0]
7048 if first_char in ["@", "&"]:
7049 self.assertEqual(lines_prod[j], lines_comp[j])
7050 else:
7051
7052
7053 x_prod, y_prod, y_prod_err = lines_prod[j].split()
7054 x_comp, y_comp, y_comp_err = lines_comp[j].split()
7055 self.assertAlmostEqual(float(x_prod), float(x_comp))
7056 self.assertAlmostEqual(float(y_prod), float(y_comp))
7057
7058
7060 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
7061
7062 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
7063
7064 This uses the automatic analysis, with missing loading R1.
7065
7066 """
7067
7068
7069 cluster_ids = [
7070 ":13@N",
7071 ":15@N",
7072 ":16@N",
7073 ":25@N",
7074 ":26@N",
7075 ":28@N",
7076 ":39@N",
7077 ":40@N",
7078 ":41@N",
7079 ":43@N",
7080 ":44@N",
7081 ":45@N",
7082 ":49@N",
7083 ":52@N",
7084 ":53@N"]
7085
7086
7087 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False)
7088
7089
7090 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
7091
7092
7093 GRID_INC = None
7094
7095
7096 MC_NUM = 3
7097
7098
7099 MODSEL = 'AIC'
7100
7101
7102
7103 OPT_FUNC_TOL = 1e-25
7104 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
7105 OPT_MAX_ITERATIONS = 10000000
7106 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
7107
7108 result_dir_name = ds.tmpdir
7109
7110
7111 for curspin in cluster_ids:
7112 self.interpreter.relax_disp.cluster('free spins', curspin)
7113
7114 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
7115
7116
7117
7118
7119
7120
7121
7122
7123 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
7124
7125
7126
7127 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000"
7128
7129 r1_fit = True
7130
7131
7132 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit)
7133
7134
7135 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7136
7137
7139 """Test the operation of the relax_disp.r2eff_read user function."""
7140
7141
7142 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz'
7143
7144
7145 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1)
7146
7147
7148 id = 'test'
7149
7150
7151 self.interpreter.spectrometer.frequency(id=id, frq=800e6)
7152 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
7153
7154
7155 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3)
7156
7157
7158 data = [
7159 ['cpmg_frqs', {'test': 66.667}],
7160 ['cpmg_frqs_list', [66.667]],
7161 ['dispersion_points', 1],
7162 ['exp_type', {'test': 'SQ CPMG'}],
7163 ['exp_type_list', ['SQ CPMG']],
7164 ['spectrometer_frq', {'test': 800000000.0}],
7165 ['spectrometer_frq_count', 1],
7166 ['spectrometer_frq_list', [800000000.0]],
7167 ['spectrum_ids', ['test']]
7168 ]
7169 for name, value in data:
7170
7171 self.assert_(hasattr(cdp, name))
7172
7173
7174 obj = getattr(cdp, name)
7175 self.assertEqual(obj, value)
7176
7177
7178 data = [
7179 [1, 2.3035747e+04, 8.5467725e+01],
7180 [2, 9.9629762e+04, 2.8322033e+02],
7181 [3, 9.5663137e+04, 2.8632929e+02],
7182 [4, 1.7089893e+05, 3.1089428e+02],
7183 [5, 4.7323876e+04, 1.0084269e+02],
7184 [6, 2.0199122e+04, 1.0135220e+02],
7185 [7, 1.6655488e+05, 3.1609061e+02],
7186 [8, 9.0061074e+04, 1.9176585e+02],
7187 [10, 8.4726204e+04, 2.8898155e+02],
7188 [11, 1.5050233e+05, 4.3138029e+02],
7189 [12, 9.2998531e+04, 3.0440191e+02],
7190 [13, 1.6343507e+05, 3.3144097e+02],
7191 [14, 1.0137301e+05, 3.7314642e+02],
7192 [15, 8.3407837e+04, 1.6546473e+02],
7193 [16, 1.3819126e+05, 3.3388517e+02],
7194 [17, 1.1010490e+05, 3.5639222e+02],
7195 [18, 9.4324035e+04, 3.2343585e+02],
7196 [19, 1.1135179e+05, 3.0706671e+02],
7197 [20, 7.6339410e+04, 1.7377460e+02],
7198 [21, 6.2008453e+04, 1.7327150e+02],
7199 [22, 1.0590404e+05, 2.4814635e+02],
7200 [23, 1.0630198e+05, 2.3601100e+02],
7201 [24, 7.2996320e+04, 1.4952465e+02],
7202 [25, 9.5486742e+04, 2.7080766e+02],
7203 [26, 5.8067989e+04, 1.6820462e+02],
7204 [27, -1.7168510e+04, 2.2519560e+02],
7205 [28, 1.6891473e+05, 2.3497525e+02],
7206 [29, 9.4038555e+04, 2.0357593e+02],
7207 [30, 2.1386951e+04, 2.2153532e+02],
7208 [31, 9.3982899e+04, 2.0937056e+02],
7209 [32, 8.6097484e+04, 2.3868467e+02],
7210 [33, 1.0194337e+05, 2.7370704e+02],
7211 [34, 8.5683111e+04, 2.0838076e+02],
7212 [35, 8.6985768e+04, 2.0889310e+02],
7213 [36, 8.6011237e+04, 1.7498390e+02],
7214 [37, 1.0984097e+05, 2.7622998e+02],
7215 [38, 8.7017879e+04, 2.6547994e+02],
7216 [39, 9.1682649e+04, 5.2777676e+02],
7217 [40, 7.6370440e+04, 1.9873214e+02],
7218 [41, 9.1393531e+04, 2.4483824e+02],
7219 [42, 1.1017111e+05, 2.8020699e+02],
7220 [43, 9.4552366e+04, 3.4394150e+02],
7221 [44, 1.2858281e+05, 6.8449252e+02],
7222 [45, 7.4583525e+04, 1.9544210e+02],
7223 [46, 9.2087490e+04, 2.0491066e+02],
7224 [47, 9.7507255e+04, 2.5162839e+02],
7225 [48, 1.0033842e+05, 2.7566430e+02],
7226 [49, 1.3048305e+05, 2.6797466e+02],
7227 [50, 1.0546796e+05, 1.9304384e+02],
7228 [51, 9.3099697e+04, 2.0773311e+02],
7229 [52, 4.6863758e+04, 1.3169068e+02],
7230 [53, 6.1055806e+04, 1.5448477e+02],
7231 [55, 6.8629994e+04, 1.6868673e+02],
7232 [56, 1.1005552e+05, 2.1940465e+02],
7233 [57, 1.0572760e+05, 1.9768486e+02],
7234 [58, 1.1176950e+05, 3.0009610e+02],
7235 [59, 9.8758603e+04, 3.3803895e+02],
7236 [60, 9.9517201e+04, 3.5137994e+02],
7237 [61, 5.4357946e+04, 2.5896579e+02],
7238 [62, 1.0899978e+05, 2.8720371e+02],
7239 [63, 8.4549759e+04, 4.1401837e+02],
7240 [64, 5.5014550e+04, 2.1135781e+02],
7241 [65, 8.0569666e+04, 2.3249709e+02],
7242 [66, 1.2936610e+05, 3.5218725e+02],
7243 [67, 3.6438010e+04, 8.7924003e+01],
7244 [70, 3.8763157e+04, 1.3325040e+02],
7245 [71, 8.5711411e+04, 2.9316183e+02],
7246 [72, 3.3211541e+04, 1.2182123e+02],
7247 [73, 3.2070576e+04, 1.2305430e+02]
7248 ]
7249 for res_num, value, error in data:
7250
7251 spin = return_spin(spin_id=":%s"%res_num)
7252
7253
7254 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value)
7255 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7256
7257
7259 """Test the operation of the relax_disp.r2eff_read_spin user function."""
7260
7261
7262 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005'
7263
7264
7265 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H')
7266 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N')
7267 self.interpreter.spin.isotope('1H', spin_id='@H')
7268 self.interpreter.spin.isotope('15N', spin_id='@N')
7269
7270
7271 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0]
7272 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0]
7273 ids = []
7274 for value in H_disp_points:
7275 ids.append('1H_CPMG_%s' % value)
7276 for value in N_disp_points:
7277 ids.append('15N_CPMG_%s' % value)
7278 print("\n\nThe experiment IDs are %s." % ids)
7279
7280
7281 for id in ids:
7282 self.interpreter.spectrometer.frequency(id=id, frq=500e6)
7283 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
7284 for value in H_disp_points:
7285 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value)
7286 for value in N_disp_points:
7287 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value)
7288
7289
7290 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]:
7291
7292 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3)
7293
7294
7295 data = [
7296 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}],
7297 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]],
7298 ['dispersion_points', 24],
7299 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}],
7300 ['exp_type_list', ['SQ CPMG']],
7301 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}],
7302 ['spectrometer_frq_count', 1],
7303 ['spectrometer_frq_list', [500000000.0]],
7304 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']]
7305 ]
7306 for name, value in data:
7307
7308 self.assert_(hasattr(cdp, name))
7309
7310
7311 obj = getattr(cdp, name)
7312 if not isinstance(data, dict):
7313 self.assertEqual(obj, value)
7314
7315
7316 else:
7317 for id in ids:
7318 self.assertEqual(obj[id], value[id])
7319
7320
7321 h_data = [
7322 [ 67.0, 21.47924, 0.42958],
7323 [ 133.0, 16.73898, 0.33478],
7324 [ 267.0, 9.97357, 0.19947],
7325 [ 400.0, 8.23877, 0.24737],
7326 [ 533.0, 7.59290, 0.24263],
7327 [ 667.0, 7.45843, 0.24165],
7328 [ 800.0, 7.11222, 0.23915],
7329 [ 933.0, 7.40880, 0.24129],
7330 [1067.0, 6.55191, 0.16629],
7331 [1600.0, 6.72177, 0.23637],
7332 [2133.0, 7.09629, 0.23904],
7333 [2667.0, 7.14675, 0.23940]
7334 ]
7335 for disp_point, value, error in h_data:
7336 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point
7337 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value)
7338 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error)
7339 n_data = [
7340 [ 50.0, 27.15767, 0.54315],
7341 [ 100.0, 26.55781, 0.53116],
7342 [ 150.0, 24.73462, 0.49469],
7343 [ 200.0, 20.98617, 0.41972],
7344 [ 250.0, 17.82442, 0.35649],
7345 [ 300.0, 15.55352, 0.31107],
7346 [ 350.0, 13.78958, 0.27579],
7347 [ 400.0, 12.48334, 0.24967],
7348 [ 500.0, 11.55724, 0.23114],
7349 [ 600.0, 10.53874, 0.21077],
7350 [ 700.0, 10.07395, 0.20148],
7351 [ 800.0, 9.62952, 0.19259],
7352 [ 900.0, 9.49994, 0.19000],
7353 [1000.0, 8.71350, 0.17427]
7354 ]
7355 for disp_point, value, error in n_data:
7356 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point
7357 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value)
7358 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7359
7360
7362 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis."""
7363
7364
7365 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7366
7367
7369 """Test the reading of a file containing r2eff values."""
7370
7371
7372 self.interpreter.residue.create(1, 'Gly')
7373 self.interpreter.residue.create(2, 'Gly')
7374 self.interpreter.residue.create(3, 'Gly')
7375
7376
7377 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4)
7378
7379
7380 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000)
7381 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003)
7382 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7383
7384
7386 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}.
7387
7388 User function to set the R20 parameters in the default grid search using the minimum R2eff value.
7389
7390 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009
7391 'SOD1-WT' CPMG data to the CR72 dispersion model.
7392
7393 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz.
7394 Data is for experiment at 25 degree Celcius.
7395 """
7396
7397
7398 pipe_name = 'base pipe'
7399 pipe_type = 'relax_disp'
7400 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
7401 select_spin_index = list(range(0, 1))
7402 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index)
7403
7404
7405 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6)
7406 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6)
7407
7408
7409 MODEL = "CR72"
7410
7411
7412 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
7413 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
7414 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
7415
7416
7417 self.interpreter.relax_disp.select_model(model=MODEL)
7418
7419
7420 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
7421
7422
7423 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7424
7425 spin_params = spin.params
7426
7427
7428 if spin_id == ":10@N":
7429 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106)
7430 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649)
7431
7432
7433 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn))
7434
7435
7436 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500])
7437
7438
7439 self.assert_(spin.r2[r20_key_600] > 0.0)
7440 self.assert_(spin.r2[r20_key_500] > 0.0)
7441
7442
7443 r2eff_600 = []
7444 r2eff_500 = []
7445 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
7446
7447 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
7448
7449
7450 r2eff = spin.r2eff[data_key]
7451 if frq == 599.8908617*1E6:
7452 r2eff_600.append(r2eff)
7453 elif frq == 499.862139*1E6:
7454 r2eff_500.append(r2eff)
7455
7456
7457 r2eff_600.sort()
7458 r2eff_500.sort()
7459
7460
7461 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600)))
7462 print(r2eff_600)
7463 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600))
7464 print("")
7465
7466 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500)))
7467 print(r2eff_500)
7468 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500))
7469 print("")
7470
7471 print("###########################################")
7472 print("Trying GRID SEARCH for minimum R2eff values")
7473
7474
7475 GRID_INC = 5
7476
7477 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1)
7478
7479
7480
7481 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL)
7482 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
7483 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
7484
7485
7486 self.interpreter.relax_disp.select_model(model=MODEL)
7487
7488
7489 for param in spin_params:
7490 print("Setting standard parameter for param: %s"%param)
7491 self.interpreter.value.set(param=param, index=None)
7492
7493
7494 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7495
7496 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn))
7497
7498
7499 self.assertEqual(spin.r2[r20_key_600], 10.00)
7500 self.assertEqual(spin.r2[r20_key_500], 10.00)
7501 self.assertEqual(spin.pA, 0.9)
7502 self.assertEqual(spin.dw, 1.0)
7503 self.assertEqual(spin.kex, 1000.0)
7504
7505 print("###########################################")
7506 print("Trying GRID SEARCH for standard R2eff values")
7507
7508
7509 GRID_INC = 5
7510
7511 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1)
7512
7513
7514
7515 GRID_INC = 5
7516
7517
7518 MC_NUM = 3
7519
7520
7521 MODSEL = 'AIC'
7522
7523
7524
7525 OPT_FUNC_TOL = 1e-1
7526 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
7527 OPT_MAX_ITERATIONS = 1000
7528 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
7529
7530
7531 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7532
7533
7535 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod."""
7536
7537
7538 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data'
7539
7540
7541 file_name = '128_0_FT.ft2'
7542
7543
7544 get_output = show_apod_extract(file_name=file_name, dir=data_path)
7545
7546
7547
7548
7549 show_apod_ver = [
7550 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name),
7551 'REMARK Automated Noise Std Dev in Processed Data: 8583.41',
7552 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558',
7553 '',
7554 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR',
7555 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e']
7556
7557
7558
7559
7560 for i, line in enumerate(show_apod_ver):
7561 line_ver = get_output[i]
7562
7563 print(line)
7564 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:':
7565 continue
7566
7567 self.assertEqual(line, line_ver)
7568
7569
7571 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod."""
7572
7573
7574 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data'
7575
7576
7577 file_name = '128_0_FT.ft2'
7578
7579
7580 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path)
7581
7582
7583 self.assertEqual(rmsd, 8583.41)
7584
7585
7587 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files."""
7588
7589
7590 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data'
7591
7592
7593 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir)
7594
7595
7596 for wfile_path in wfile_paths:
7597
7598 get_data = extract_data(file=wfile_path)
7599
7600
7601 test = float(get_data[0][0])
7602
7603
7604 self.assertEqual(test, 8583.41)
7605
7606
7608 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file."""
7609
7610
7611 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data'
7612
7613
7614 file_name = '128_0_FT.ft2'
7615
7616
7617 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir)
7618
7619
7620 get_data = extract_data(file=wfile_path)
7621
7622
7623 test = float(get_data[0][0])
7624
7625
7626 self.assertEqual(test, 8583.41)
7627
7628
7630 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}.
7631
7632 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009
7633 'SOD1-WT' CPMG data to the CR72 dispersion model.
7634
7635 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz.
7636 Data is for experiment at 25 degree Celcius.
7637
7638 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important.
7639 """
7640
7641
7642 pipe_name = 'base pipe'
7643 pipe_type = 'relax_disp'
7644 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
7645 select_spin_index = list(range(0, 1))
7646 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index)
7647
7648
7649 repl_A = ['Z_A1', 'Z_A15']
7650 repl_B = ['Z_B1', 'Z_B18']
7651
7652
7653 spectrum_ids_A = []
7654 spectrum_ids_B = []
7655 for spectrum_id in cdp.spectrum_ids:
7656 if "A" in spectrum_id:
7657 spectrum_ids_A.append(spectrum_id)
7658 elif "B" in spectrum_id:
7659 spectrum_ids_B.append(spectrum_id)
7660
7661
7662 delattr(cdp, "var_I")
7663 delattr(cdp, "sigma_I")
7664
7665
7666 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A)
7667 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B)
7668
7669
7670 Errors_A_B = []
7671 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7672 A_err = spin.peak_intensity_err[spectrum_ids_A[0]]
7673 B_err = spin.peak_intensity_err[spectrum_ids_B[0]]
7674 Errors_A_B.append([A_err, B_err])
7675
7676
7677 delattr(cdp, "var_I")
7678 delattr(cdp, "sigma_I")
7679
7680
7681 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B)
7682 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A)
7683
7684
7685 Errors_B_A = []
7686 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7687 A_err = spin.peak_intensity_err[spectrum_ids_A[0]]
7688 B_err = spin.peak_intensity_err[spectrum_ids_B[0]]
7689 Errors_B_A.append([A_err, B_err])
7690
7691
7692 for i in range(len(Errors_A_B)):
7693 Error_A_B = Errors_A_B[i]
7694 Error_B_A = Errors_B_A[i]
7695 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4)
7696 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4)
7697
7698
7699 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2)
7700 std_A_fix = 2785.7263335738567
7701
7702 for id_A in spectrum_ids_A:
7703 self.assertEqual(cdp.sigma_I[id_A], std_A)
7704 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7)
7705
7706 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2)
7707 std_B_fix = 4967.3772030667988
7708
7709 for id_B in spectrum_ids_B:
7710 self.assertEqual(cdp.sigma_I[id_B], std_B)
7711 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7712
7713
7715 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}.
7716
7717 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009
7718 'SOD1-WT' CPMG data to the CR72 dispersion model.
7719
7720 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz.
7721 Data is for experiment at 25 degree Celcius.
7722 """
7723
7724
7725 pipe_name = 'base pipe'
7726 pipe_type = 'relax_disp'
7727 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
7728 select_spin_index = list(range(0, 2))
7729 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index)
7730
7731
7732 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6)
7733 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6)
7734
7735
7736 MODEL = "CR72"
7737
7738
7739 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
7740 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
7741 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
7742
7743
7744 self.interpreter.relax_disp.select_model(model=MODEL)
7745
7746
7747 GRID_INC = 7
7748
7749
7750 grid_results = []
7751 mini_results = []
7752 clust_results = []
7753
7754
7755 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
7756
7757
7758 self.interpreter.relax_disp.insignificance(level=1.0)
7759
7760
7761 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1)
7762
7763
7764 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7765
7766 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
7767
7768
7769
7770 set_func_tol = 1e-9
7771 set_max_iter = 100000
7772 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
7773
7774
7775 pA_values = []
7776 kex_values = []
7777 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7778
7779 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
7780
7781
7782 pA_values.append(spin.pA)
7783
7784
7785 kex_values.append(spin.kex)
7786
7787 print("\n# Now print before and after minimisation.\n")
7788
7789
7790 for i in range(len(grid_results)):
7791
7792 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
7793 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
7794
7795 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn))
7796 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn))
7797
7798
7799
7800 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL)
7801 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER)
7802 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER)
7803
7804
7805 self.interpreter.relax_disp.select_model(model=MODEL)
7806
7807
7808 cluster_id = 'clust'
7809
7810
7811 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7812 self.interpreter.relax_disp.cluster(cluster_id, spin_id)
7813
7814
7815 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER)
7816
7817
7818 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7819 print(pA_values)
7820
7821 self.assertEqual(median(pA_values), spin.pA)
7822
7823
7824 self.assertEqual(median(kex_values), spin.kex)
7825
7826
7827 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
7828
7829
7830 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7831
7832 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
7833
7834
7835 clust_pA = spin.pA
7836 clust_kex = spin.kex
7837
7838 print("\n# Now testing.\n")
7839
7840
7841 test_res = {}
7842 test_res[':10@N'] = {}
7843 test_res[':10@N']['r2600'] = 18.429755324773360
7844 test_res[':10@N']['r2500'] = 16.981349161968630
7845 test_res[':10@N']['dw'] = 2.700755859433969
7846 test_res[':10@N']['pA'] = 0.971531659288657
7847 test_res[':10@N']['kex'] = 3831.766337047963134
7848 test_res[':11@N'] = {}
7849 test_res[':11@N']['r2600'] = 18.193409421115213
7850 test_res[':11@N']['r2500'] = 17.308838135567765
7851 test_res[':11@N']['dw'] = 2.706650302761793
7852 test_res[':11@N']['pA'] = 0.971531659288657
7853 test_res[':11@N']['kex'] = 3831.766337047963134
7854
7855
7856 for i in range(len(grid_results)):
7857
7858 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
7859 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
7860 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i]
7861
7862 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn))
7863 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn))
7864 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn))
7865
7866
7867 self.assertEqual(clust_pA, c_pA)
7868 self.assertEqual(clust_kex, c_kex)
7869
7870
7871 if c_spin_id in test_res:
7872 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4)
7873 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4)
7874 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3)
7875 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5)
7876 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
7877
7878
7879
7880
7881
8048
8049
8051 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data.
8052
8053 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period.
8054 """
8055
8056
8057 self.interpreter.reset()
8058
8059
8060 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP'
8061 self.interpreter.state.load(data_path+sep+'r2eff_values')
8062
8063
8064 model = 'MMQ CR72'
8065 pipe_name = "%s - relax_disp" % model
8066 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp')
8067 self.interpreter.pipe.switch(pipe_name=pipe_name)
8068
8069
8070 self.interpreter.relax_disp.select_model(model=model)
8071
8072
8073 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137")
8074
8075
8076 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
8077
8078
8079 spin135S = cdp.mol[0].res[0].spin[0]
8080 spin135F = cdp.mol[0].res[0].spin[1]
8081 spin137S = cdp.mol[0].res[1].spin[0]
8082 spin137F = cdp.mol[0].res[1].spin[1]
8083
8084
8085 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
8086 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
8087
8088
8089 spin135S.pA = 0.836591763632
8090 spin135S.kex = 241.806525261
8091
8092
8093 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715}
8094 spin135S.dw = 0.583003118785
8095 spin135S.dwH = 0.0361441944301
8096
8097 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389}
8098 spin135F.dw = 0.805849745104
8099 spin135F.dwH = 0.0215791945715
8100
8101 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934}
8102 spin137S.dw = 0.688107568372
8103 spin137S.dwH = 0.0344463604043
8104
8105 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101}
8106 spin137F.dw = 0.94978299907
8107 spin137F.dwH = 1.4818877939e-07
8108
8109
8110 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000)
8111
8112
8113 print("\n\nOptimised parameters:\n")
8114 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)"))
8115 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1]))
8116 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2]))
8117 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA))
8118 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw))
8119 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH))
8120 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex))
8121 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2))
8122 print("\n # Set the cluster specific parameters (only for the first spin).")
8123 print(" spin135S.pA = %s" % spin135S.pA)
8124 print(" spin135S.kex = %s" % spin135S.kex)
8125 print("\n # Set the initial parameter values.")
8126 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2]))
8127 print(" spin135S.dw = %s" % spin135S.dw)
8128 print(" spin135S.dwH = %s" % spin135S.dwH)
8129 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2]))
8130 print(" spin135F.dw = %s" % spin135F.dw)
8131 print(" spin135F.dwH = %s" % spin135F.dwH)
8132 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2]))
8133 print(" spin137S.dw = %s" % spin137S.dw)
8134 print(" spin137S.dwH = %s" % spin137S.dwH)
8135 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2]))
8136 print(" spin137F.dw = %s" % spin137F.dw)
8137 print(" spin137F.dwH = %s" % spin137F.dwH)
8138
8139
8140 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4)
8141 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4)
8142 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4)
8143 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4)
8144 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4)
8145 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4)
8146 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4)
8147
8148
8149 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4)
8150 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4)
8151 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4)
8152 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4)
8153 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4)
8154 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4)
8155 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4)
8156
8157
8158 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4)
8159 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4)
8160 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4)
8161 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4)
8162 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4)
8163 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4)
8164 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4)
8165
8166
8167 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4)
8168 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4)
8169 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4)
8170 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4)
8171 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4)
8172 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4)
8173 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8174
8175
8177 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data.
8178
8179 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period.
8180 """
8181
8182
8183 self.interpreter.reset()
8184
8185
8186 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP'
8187 self.interpreter.state.load(data_path+sep+'r2eff_values')
8188
8189
8190 model = 'NS MMQ 2-site'
8191 pipe_name = "%s - relax_disp" % model
8192 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp')
8193 self.interpreter.pipe.switch(pipe_name=pipe_name)
8194
8195
8196 self.interpreter.relax_disp.select_model(model=model)
8197
8198
8199 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137")
8200
8201
8202 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
8203
8204
8205 spin135S = cdp.mol[0].res[0].spin[0]
8206 spin135F = cdp.mol[0].res[0].spin[1]
8207 spin137S = cdp.mol[0].res[1].spin[0]
8208 spin137F = cdp.mol[0].res[1].spin[1]
8209
8210
8211 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
8212 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
8213
8214
8215 spin135S.pA = 0.847378444499757
8216 spin135S.kex = 264.055604934724329
8217
8218
8219 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299}
8220 spin135S.dw = 0.585574008745351
8221 spin135S.dwH = 0.000000000000002
8222
8223 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893}
8224 spin135F.dw = 0.856699277665748
8225 spin135F.dwH = 0.000000000582587
8226
8227 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824}
8228 spin137S.dw = 0.772904450844973
8229 spin137S.dwH = 0.183351478512970
8230
8231 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319}
8232 spin137F.dw = 0.984568590342831
8233 spin137F.dwH = 0.000000001993458
8234
8235
8236 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1)
8237
8238
8239 print("\n\nOptimised parameters:\n")
8240 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)"))
8241 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1]))
8242 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2]))
8243 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA))
8244 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw))
8245 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH))
8246 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex))
8247 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2))
8248
8249
8250 return
8251
8252
8253 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4)
8254 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4)
8255 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4)
8256 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4)
8257 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4)
8258 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4)
8259 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1)
8260
8261
8262 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4)
8263 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4)
8264 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4)
8265 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4)
8266 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4)
8267 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4)
8268 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1)
8269
8270
8271 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4)
8272 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4)
8273 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4)
8274 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4)
8275 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4)
8276 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4)
8277 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1)
8278
8279
8280 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4)
8281 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4)
8282 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4)
8283 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4)
8284 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4)
8285 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4)
8286 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8287
8288
8290 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data."""
8291
8292
8293 self.setup_tp02_data_to_ns_r1rho_2site()
8294
8295
8296 spin1 = cdp.mol[0].res[0].spin[0]
8297 spin2 = cdp.mol[0].res[1].spin[0]
8298
8299
8300 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8301 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8302
8303
8304 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4)
8305 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4)
8306 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4)
8307 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4)
8308 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4)
8309 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4)
8310
8311
8312 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4)
8313 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4)
8314 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4)
8315 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4)
8316 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4)
8317 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8318
8319
8321 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering."""
8322
8323
8324 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True)
8325
8326
8327 spin1 = cdp.mol[0].res[0].spin[0]
8328 spin2 = cdp.mol[0].res[1].spin[0]
8329
8330
8331 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8332 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8333
8334
8335 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4)
8336 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4)
8337 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4)
8338 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4)
8339 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4)
8340 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4)
8341
8342
8343 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4)
8344 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4)
8345 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4)
8346 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4)
8347 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4)
8348 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8349
8350
8352 """Test the dispersion 'MP05' model fitting against the 'TP02' test data."""
8353
8354
8355 ds.fixed = True
8356 ds.models = ['R2eff', 'MP05']
8357
8358
8359 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py')
8360
8361
8362 self.interpreter.pipe.switch('MP05 - relax_disp')
8363
8364
8365 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]]
8366 pA = [0.775055484521586, 0.500000000036595]
8367 kex = [1235.20361276079, 2378.31403454691]
8368 delta_omega = [7.08194146569694, 5.4083562844306]
8369 chi2 = [0.0370400968727768, 0.182141732163934]
8370
8371
8372 spin1 = cdp.mol[0].res[0].spin[0]
8373 spin2 = cdp.mol[0].res[1].spin[0]
8374
8375
8376 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8377 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8378
8379
8380 print("\n\nOptimised parameters:\n")
8381 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
8382 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
8383 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
8384 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA))
8385 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw))
8386 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex))
8387 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
8388
8389
8390 spin_index = 0
8391 for spin, spin_id in spin_loop(return_id=True):
8392
8393 print("\nSpin %s." % spin_id)
8394
8395
8396 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4)
8397 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4)
8398 self.assertAlmostEqual(spin.pA, pA[spin_index], 3)
8399 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
8400 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3)
8401 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3)
8402
8403
8404 spin_index += 1
8405
8406
8408 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data."""
8409
8410
8411 ds.fixed = True
8412 ds.models = ['R2eff', 'TAP03']
8413
8414
8415 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py')
8416
8417
8418 self.interpreter.pipe.switch('TAP03 - relax_disp')
8419
8420
8421 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]]
8422 pA = [0.775042569092891, 0.500000000229685]
8423 kex = [1235.20852748765, 2379.47085580169]
8424 delta_omega = [7.08176806468445, 5.40708372863538]
8425 chi2 = [0.0371366837083293, 0.182212857256044]
8426
8427
8428 spin1 = cdp.mol[0].res[0].spin[0]
8429 spin2 = cdp.mol[0].res[1].spin[0]
8430
8431
8432 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8433 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8434
8435
8436 print("\n\nOptimised parameters:\n")
8437 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
8438 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
8439 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
8440 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA))
8441 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw))
8442 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex))
8443 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
8444
8445
8446 self.interpreter.pipe.switch('TAP03 - relax_disp')
8447 spin_index = 0
8448 for spin, spin_id in spin_loop(return_id=True):
8449
8450 print("\nSpin %s." % spin_id)
8451
8452
8453 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4)
8454 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4)
8455 self.assertAlmostEqual(spin.pA, pA[spin_index], 3)
8456 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
8457 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3)
8458 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3)
8459
8460
8461 spin_index += 1
8462
8463
8465 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data."""
8466
8467
8468 ds.fixed = True
8469
8470
8471 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py')
8472
8473
8474 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]]
8475 pA = 0.7654321
8476 kex = 1234.56789
8477 delta_omega = [7.0, 9.0]
8478
8479
8480 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8481 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8482
8483
8484 self.interpreter.pipe.switch('TP02 - relax_disp')
8485 spin_index = 0
8486 for spin, spin_id in spin_loop(return_id=True):
8487
8488 print("\nSpin %s." % spin_id)
8489
8490
8491 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4)
8492 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4)
8493 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
8494 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3)
8495
8496
8497 spin_index += 1
8498
8499
8501 """System test of the value.write function to write intensities for an R1rho setup.
8502 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write.
8503
8504 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}.
8505 """
8506
8507
8508 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
8509 self.interpreter.state.load(statefile, force=True)
8510
8511
8512 int_filepath = ds.tmpdir+sep+'int.out'
8513
8514
8515
8516 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True)
8517
8518
8519 self.assert_(access(int_filepath, F_OK))
8520
8521
8522 int_file = open(int_filepath, 'r')
8523
8524
8525 for line in int_file:
8526
8527 if line[0] == "#":
8528 continue
8529
8530
8531 linesplit = line.split()
8532
8533
8534 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I":
8535 self.assertEqual(linesplit[5], "115571.4")
8536 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S":
8537 self.assertEqual(linesplit[5], "68377.52")
8538 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S":
8539 self.assertEqual(linesplit[5], "9141.689")
8540 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A":
8541 self.assertEqual(linesplit[5], "29123.77")
8542 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L":
8543 self.assertEqual(linesplit[5], "58914.94")
8544
8545
8546 int_file.close()
8547
8548
8550 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup.
8551
8552 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}.
8553 """
8554
8555
8556 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
8557 self.interpreter.state.load(statefile, force=True)
8558
8559
8560 theta_filepath = ds.tmpdir+sep+'theta.out'
8561
8562
8563 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True)
8564
8565
8566 self.assert_(access(theta_filepath, F_OK))
8567
8568
8569 theta_file = open(theta_filepath, 'r')
8570
8571
8572 for line in theta_file:
8573
8574 if line[0] == "#":
8575 continue
8576
8577 print(line[:-1])
8578
8579
8580 linesplit = line.split()
8581
8582
8583 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I":
8584 self.assertNotEqual(linesplit[5], "None")
8585 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S":
8586 self.assertNotEqual(linesplit[5], "None")
8587 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S":
8588 self.assertNotEqual(linesplit[5], "None")
8589 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A":
8590 self.assertNotEqual(linesplit[5], "None")
8591 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L":
8592 self.assertNotEqual(linesplit[5], "None")
8593
8594
8595 theta_file.close()
8596
8597
8599 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup.
8600
8601 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}.
8602 """
8603
8604
8605 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
8606 self.interpreter.state.load(statefile, force=True)
8607
8608
8609 w_eff_filepath = ds.tmpdir+sep+'w_eff.out'
8610
8611
8612 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True)
8613
8614
8615 self.assert_(access(w_eff_filepath, F_OK))
8616
8617
8618 w_eff_file = open(w_eff_filepath, 'r')
8619
8620
8621 for line in w_eff_file:
8622
8623 if line[0] == "#":
8624 continue
8625
8626 print(line[:-1])
8627
8628
8629 linesplit = line.split()
8630
8631
8632 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I":
8633 self.assertNotEqual(linesplit[5], "None")
8634 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S":
8635 self.assertNotEqual(linesplit[5], "None")
8636 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S":
8637 self.assertNotEqual(linesplit[5], "None")
8638 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A":
8639 self.assertNotEqual(linesplit[5], "None")
8640 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L":
8641 self.assertNotEqual(linesplit[5], "None")
8642
8643
8644 w_eff_file.close()
8645
8646
8648 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup.
8649
8650 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}.
8651 """
8652
8653
8654 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2'
8655 self.interpreter.state.load(statefile, force=True)
8656
8657
8658 pipe_name = 'base pipe'
8659 pipe_bundle = 'relax_disp'
8660 pipe_type = 'relax_disp'
8661
8662
8663 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
8664
8665
8666 self.interpreter.deselect.all()
8667
8668
8669 select_spin_ids = [
8670 ":13@N",
8671 ":15@N",
8672 ":16@N",
8673 ":25@N",
8674 ":26@N",
8675 ":28@N",
8676 ":39@N",
8677 ":40@N",
8678 ":41@N",
8679 ":43@N",
8680 ":44@N",
8681 ":45@N",
8682 ":49@N",
8683 ":52@N",
8684 ":53@N"]
8685
8686
8687 for curspin in select_spin_ids:
8688 print("Selecting spin %s"%curspin)
8689 self.interpreter.deselect.reverse(spin_id=curspin)
8690
8691
8692 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
8693
8694
8695 MODELS = ['R2eff']
8696
8697
8698 GRID_INC = 4
8699
8700
8701 MC_NUM = 3
8702
8703
8704 MODSEL = 'AIC'
8705
8706
8707
8708 OPT_FUNC_TOL = 1e-1
8709 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
8710 OPT_MAX_ITERATIONS = 1000
8711 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
8712
8713
8714 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL)
8715
8716
8717
8718 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out'
8719 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out'
8720
8721
8722 self.assert_(access(theta_filepath, F_OK))
8723 self.assert_(access(w_eff_filepath, F_OK))
8724
8725
8726 theta_file = open(theta_filepath, 'r')
8727 theta_result = [
8728 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n",
8729 "#\n",
8730 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n",
8731 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8732 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8733 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8734 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8735 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8736 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8737 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8738 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n",
8739 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8740 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n",
8741 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n",
8742 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8743 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8744 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8745 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8746 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8747 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n",
8748 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n",
8749 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8750 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n",
8751 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8752 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8753 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8754 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8755 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8756 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8757 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8758 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8759 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8760 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n",
8761 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n",
8762 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n",
8763 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8764 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n",
8765 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n",
8766 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n",
8767 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8768 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8769 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n",
8770 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8771 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8772 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n",
8773 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n",
8774 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8775 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8776 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8777 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8778 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n"
8779 ]
8780
8781 lines = theta_file.readlines()
8782 for i in range(len(lines)):
8783
8784 if theta_result[i][0] == "#":
8785 self.assertEqual(theta_result[i], lines[i])
8786
8787 if theta_result[i] == lines[i]:
8788 self.assertEqual(theta_result[i], lines[i])
8789
8790 else:
8791
8792 print(theta_result[i])
8793 print(lines[i])
8794
8795
8796 self.assertEqual(theta_result[i][:62], lines[i][:62])
8797
8798
8799 theta_result_s = theta_result[i][62:].split()[::2]
8800 print(theta_result_s )
8801 lines_s = lines[i][62:].split()[::2]
8802 print(lines_s)
8803
8804 for j in range(len(lines_s)):
8805 print(theta_result_s[j], lines_s[j])
8806
8807 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14)
8808
8809
8810 theta_file.close()
8811
8812 w_eff_file = open(w_eff_filepath, 'r')
8813 w_eff_result = [
8814 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n",
8815 "#\n",
8816 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n",
8817 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8818 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8819 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8820 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8821 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8822 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8823 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8824 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n",
8825 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8826 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n",
8827 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n",
8828 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8829 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8830 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8831 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8832 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8833 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n",
8834 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n",
8835 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8836 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n",
8837 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8838 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8839 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8840 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8841 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8842 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8843 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8844 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8845 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8846 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n",
8847 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n",
8848 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n",
8849 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8850 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n",
8851 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n",
8852 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n",
8853 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8854 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8855 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n",
8856 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8857 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8858 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n",
8859 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n",
8860 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8861 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8862 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8863 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n",
8864 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n"
8865 ]
8866
8867 lines = w_eff_file.readlines()
8868 for i in range(len(lines)):
8869
8870 if w_eff_result[i][0] == "#":
8871 self.assertEqual(w_eff_result[i], lines[i])
8872
8873 if w_eff_result[i] == lines[i]:
8874 self.assertEqual(w_eff_result[i], lines[i])
8875
8876 else:
8877
8878 print(w_eff_result[i])
8879 print(lines[i])
8880
8881
8882 self.assertEqual(w_eff_result[i][:62], lines[i][:62])
8883
8884
8885 w_eff_result_s = w_eff_result[i][62:].split()[::2]
8886 print(w_eff_result_s )
8887 lines_s = lines[i][62:].split()[::2]
8888 print(lines_s)
8889
8890 for j in range(len(lines_s)):
8891 print(w_eff_result_s[j], lines_s[j])
8892
8893 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14)
8894
8895
8896 w_eff_file.close()
8897
8898
8900 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations.
8901
8902 This follows Task 7822.
8903 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting.
8904
8905 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
8906 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
8907 """
8908
8909
8910 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep
8911
8912
8913 pipe_name = 'base pipe'
8914 pipe_bundle = 'relax_disp'
8915 pipe_type = 'relax_disp'
8916
8917
8918 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type)
8919
8920 file = data_path + '1_setup_r1rho_GUI.py'
8921 self.interpreter.script(file=file, dir=None)
8922
8923
8924 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False)
8925
8926
8927 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
8928
8929
8930 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
8931
8932
8933 check_intensity_errors()
8934
8935
8936 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1)
8937
8938
8939 min_algor = 'Newton'
8940 constraints = True
8941 if constraints:
8942 min_options = ('%s'%(min_algor),)
8943
8944 min_algor = 'Method of Multipliers'
8945 scaling_matrix = assemble_scaling_matrix(scaling=True)
8946
8947
8948 all_spin_ids = []
8949 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8950 all_spin_ids.append(spin_id)
8951
8952 spins = spin_ids_to_containers(all_spin_ids[:1])
8953
8954
8955 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0])
8956 else:
8957 min_options = ()
8958 A, b = None, None
8959 min_options = ()
8960 sim_boot = 200
8961 scaling_list = [1.0, 1.0]
8962
8963
8964 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1)
8965
8966
8967 err_attr_list = ['r2eff_err', 'i0_err']
8968
8969 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8970
8971 for err_attr in err_attr_list:
8972 if hasattr(cur_spin, err_attr):
8973 delattr(cur_spin, err_attr)
8974
8975
8976 my_dic = {}
8977 param_key_list = []
8978 est_keys = []
8979 est_key = '-2'
8980 est_keys.append(est_key)
8981 spin_id_list = []
8982
8983 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8984
8985 my_dic[spin_id] = {}
8986
8987
8988 my_dic[spin_id][est_key] = {}
8989
8990
8991 spin_id_list.append(spin_id)
8992
8993
8994 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
8995
8996 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
8997
8998 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
8999
9000
9001 param_key_list.append(param_key)
9002
9003
9004 my_dic[spin_id][est_key][param_key] = {}
9005
9006 values = []
9007 errors = []
9008 times = []
9009 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point):
9010 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time))
9011 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True))
9012 times.append(time)
9013
9014
9015 values = asarray(values)
9016 errors = asarray(errors)
9017 times = asarray(times)
9018
9019 r2eff = getattr(cur_spin, 'r2eff')[param_key]
9020 i0 = getattr(cur_spin, 'i0')[param_key]
9021
9022 R_m_sim_l = []
9023 I0_m_sim_l = []
9024 for j in range(sim_boot):
9025 if j in range(0, 100000, 100):
9026 print("Simulation %i"%j)
9027
9028
9029
9030 I_err = []
9031 for j, error in enumerate(errors):
9032 I_error = gauss(values[j], error)
9033 I_err.append(I_error)
9034
9035 I_err = asarray(I_err)
9036
9037 x0 = [r2eff, i0]
9038 setup(num_params=len(x0), num_times=len(times), values=I_err, sd=errors, relax_times=times, scaling_matrix=scaling_list)
9039
9040
9041
9042
9043
9044
9045
9046
9047 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=func, dfunc=dfunc, d2func=d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0)
9048
9049 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j
9050 R_m_sim_l.append(R_m_sim_j)
9051 I0_m_sim_l.append(I0_m_sim_j)
9052
9053
9054 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1)
9055 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1)
9056 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim
9057 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim
9058
9059
9060 self.interpreter.relax_disp.r2eff_err_estimate()
9061
9062 est_key = '-1'
9063 est_keys.append(est_key)
9064
9065
9066 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9067
9068 my_dic[spin_id][est_key] = {}
9069
9070 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
9071
9072 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
9073
9074
9075 my_dic[spin_id][est_key][param_key] = {}
9076
9077
9078
9079 for err_attr in err_attr_list:
9080 if hasattr(cur_spin, err_attr):
9081 get_err_attr = getattr(cur_spin, err_attr)[param_key]
9082 else:
9083 get_err_attr = 0.0
9084
9085
9086 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr
9087
9088
9089
9090 mc_number_list = list(range(0, 1000, 250))
9091
9092 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim']
9093
9094
9095 for number in mc_number_list:
9096
9097 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9098
9099 for err_attr in err_attr_list:
9100 if hasattr(cur_spin, err_attr):
9101 delattr(cur_spin, err_attr)
9102
9103
9104 for sim_attr in sim_attr_list:
9105 if hasattr(cur_spin, sim_attr):
9106 delattr(cur_spin, sim_attr)
9107
9108 self.interpreter.monte_carlo.setup(number=number)
9109 self.interpreter.monte_carlo.create_data()
9110 self.interpreter.monte_carlo.initial_values()
9111 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints)
9112 self.interpreter.eliminate()
9113 self.interpreter.monte_carlo.error_analysis()
9114
9115 est_key = '%i'%number
9116 est_keys.append(est_key)
9117
9118
9119 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9120
9121 my_dic[spin_id][est_key] = {}
9122
9123 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
9124
9125 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
9126
9127
9128 my_dic[spin_id][est_key][param_key] = {}
9129
9130
9131
9132 for err_attr in err_attr_list:
9133 if hasattr(cur_spin, err_attr):
9134 get_err_attr = getattr(cur_spin, err_attr)[param_key]
9135 else:
9136 get_err_attr = 0.0
9137
9138
9139 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr
9140
9141
9142 err_attr = err_attr_list[0]
9143
9144
9145 text_list = []
9146
9147
9148 for spin_id in spin_id_list:
9149 for est_key in est_keys:
9150
9151 r2eff_err_list = []
9152
9153 for param_key in param_key_list:
9154
9155 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr]
9156
9157
9158 r2eff_err_list.append(r2eff_err)
9159
9160
9161 sum_array = sum(array(r2eff_err_list))
9162
9163
9164 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list)
9165
9166
9167 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array)
9168 text_list.append(text)
9169
9170
9171
9172 filepath = NamedTemporaryFile(delete=False).name
9173
9174 w_file = open(filepath, 'w')
9175
9176 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.")
9177
9178 for text in text_list:
9179
9180 print(text)
9181
9182
9183 w_file.write(text+"\n")
9184
9185
9186 w_file.close()
9187
9188 print("Filepath is: %s"%filepath)
9189 print("Start 'gnuplot' and write:")
9190 print("set term dumb")
9191 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9192
9193
9195 """Verification of test_r1rho_kjaergaard_missing_r1."""
9196
9197
9198
9199
9200
9201 print("\n\n################")
9202 print("Printing results")
9203 print("################\n")
9204 for model in models:
9205
9206 if model == MODEL_R2EFF:
9207 continue
9208
9209
9210 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model))
9211 print("\nModel: %s" % (model))
9212
9213
9214 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9215
9216 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
9217
9218
9219 print("Optimised parameters for spin: %s" % (spin_string))
9220 for param in cur_spin.params + ['chi2']:
9221
9222 if param in ['r1', 'r2']:
9223 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True):
9224
9225 r20_key = generate_r20_key(exp_type=exp_type, frq=frq)
9226
9227
9228 value = getattr(cur_spin, param)[r20_key]
9229
9230
9231 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value))
9232
9233
9234 if spin_id == ':52@N':
9235 if param == 'r1':
9236 if model == MODEL_NOREX:
9237 if r2eff_estimate == 'direct':
9238 self.assertAlmostEqual(value, 1.46138805)
9239 elif r2eff_estimate == 'MC2000':
9240 self.assertAlmostEqual(value, 1.46328102)
9241 elif r2eff_estimate == 'chi2_pyt':
9242 self.assertAlmostEqual(value, 1.43820629)
9243 elif model == MODEL_DPL94:
9244 if r2eff_estimate == 'direct':
9245 self.assertAlmostEqual(value, 1.44845742)
9246 elif r2eff_estimate == 'MC2000':
9247 self.assertAlmostEqual(value, 1.45019848)
9248 elif r2eff_estimate == 'chi2_pyt':
9249 self.assertAlmostEqual(value, 1.44666512)
9250 elif model == MODEL_TP02:
9251 if r2eff_estimate == 'direct':
9252 self.assertAlmostEqual(value, 1.54354392)
9253 elif r2eff_estimate == 'MC2000':
9254 self.assertAlmostEqual(value, 1.54352369)
9255 elif r2eff_estimate == 'chi2_pyt':
9256 self.assertAlmostEqual(value, 1.55964020)
9257 elif model == MODEL_TAP03:
9258 if r2eff_estimate == 'direct':
9259 self.assertAlmostEqual(value, 1.54356410)
9260 elif r2eff_estimate == 'MC2000':
9261 self.assertAlmostEqual(value, 1.54354367)
9262 elif r2eff_estimate == 'chi2_pyt':
9263 self.assertAlmostEqual(value, 1.55967157)
9264 elif model == MODEL_MP05:
9265 if r2eff_estimate == 'direct':
9266 self.assertAlmostEqual(value, 1.54356416)
9267 elif r2eff_estimate == 'MC2000':
9268 self.assertAlmostEqual(value, 1.54354372)
9269 elif r2eff_estimate == 'chi2_pyt':
9270 self.assertAlmostEqual(value, 1.55967163)
9271 elif model == MODEL_NS_R1RHO_2SITE:
9272 if r2eff_estimate == 'direct':
9273 self.assertAlmostEqual(value, 1.41359221, 5)
9274 elif r2eff_estimate == 'MC2000':
9275 self.assertAlmostEqual(value, 1.41321968, 5)
9276 elif r2eff_estimate == 'chi2_pyt':
9277 self.assertAlmostEqual(value, 1.36303129, 5)
9278
9279 elif param == 'r2':
9280 if model == MODEL_NOREX:
9281 if r2eff_estimate == 'direct':
9282 self.assertAlmostEqual(value, 11.48392439)
9283 elif r2eff_estimate == 'MC2000':
9284 self.assertAlmostEqual(value, 11.48040934)
9285 elif r2eff_estimate == 'chi2_pyt':
9286 self.assertAlmostEqual(value, 11.47224488)
9287 elif model == MODEL_DPL94:
9288 if r2eff_estimate == 'direct':
9289 self.assertAlmostEqual(value, 10.15688372, 6)
9290 elif r2eff_estimate == 'MC2000':
9291 self.assertAlmostEqual(value, 10.16304887, 6)
9292 elif r2eff_estimate == 'chi2_pyt':
9293 self.assertAlmostEqual(value, 9.20037797, 6)
9294 elif model == MODEL_TP02:
9295 if r2eff_estimate == 'direct':
9296 self.assertAlmostEqual(value, 9.72654896, 6)
9297 elif r2eff_estimate == 'MC2000':
9298 self.assertAlmostEqual(value, 9.72772726, 6)
9299 elif r2eff_estimate == 'chi2_pyt':
9300 self.assertAlmostEqual(value, 9.53948340, 6)
9301 elif model == MODEL_TAP03:
9302 if r2eff_estimate == 'direct':
9303 self.assertAlmostEqual(value, 9.72641887, 6)
9304 elif r2eff_estimate == 'MC2000':
9305 self.assertAlmostEqual(value, 9.72759374, 6)
9306 elif r2eff_estimate == 'chi2_pyt':
9307 self.assertAlmostEqual(value, 9.53926913, 6)
9308 elif model == MODEL_MP05:
9309 if r2eff_estimate == 'direct':
9310 self.assertAlmostEqual(value, 9.72641723, 6)
9311 elif r2eff_estimate == 'MC2000':
9312 self.assertAlmostEqual(value, 9.72759220, 6)
9313 elif r2eff_estimate == 'chi2_pyt':
9314 self.assertAlmostEqual(value, 9.53926778, 6)
9315 elif model == MODEL_NS_R1RHO_2SITE:
9316 if r2eff_estimate == 'direct':
9317 self.assertAlmostEqual(value, 9.34531535, 5)
9318 elif r2eff_estimate == 'MC2000':
9319 self.assertAlmostEqual(value, 9.34602793, 5)
9320 elif r2eff_estimate == 'chi2_pyt':
9321 self.assertAlmostEqual(value, 9.17631409, 5)
9322
9323
9324 else:
9325
9326 value = getattr(cur_spin, param)
9327
9328
9329 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value))
9330
9331
9332 if spin_id == ':52@N':
9333 if param == 'phi_ex':
9334 if model == MODEL_DPL94:
9335 if r2eff_estimate == 'direct':
9336 self.assertAlmostEqual(value, 0.07599563)
9337 elif r2eff_estimate == 'MC2000':
9338 self.assertAlmostEqual(value, 0.07561937)
9339 elif r2eff_estimate == 'chi2_pyt':
9340 self.assertAlmostEqual(value, 0.12946061)
9341
9342 elif param == 'pA':
9343 if model == MODEL_TP02:
9344 if r2eff_estimate == 'direct':
9345 self.assertAlmostEqual(value, 0.88827040)
9346 elif r2eff_estimate == 'MC2000':
9347 self.assertAlmostEqual(value, 0.88807487)
9348 elif r2eff_estimate == 'chi2_pyt':
9349 self.assertAlmostEqual(value, 0.87746233)
9350 elif model == MODEL_TAP03:
9351 if r2eff_estimate == 'direct':
9352 self.assertAlmostEqual(value, 0.88828922)
9353 elif r2eff_estimate == 'MC2000':
9354 self.assertAlmostEqual(value, 0.88809318)
9355 elif r2eff_estimate == 'chi2_pyt':
9356 self.assertAlmostEqual(value, 0.87747558)
9357 elif model == MODEL_MP05:
9358 if r2eff_estimate == 'direct':
9359 self.assertAlmostEqual(value, 0.88828924, 6)
9360 elif r2eff_estimate == 'MC2000':
9361 self.assertAlmostEqual(value, 0.88809321)
9362 elif r2eff_estimate == 'chi2_pyt':
9363 self.assertAlmostEqual(value, 0.87747562)
9364 elif model == MODEL_NS_R1RHO_2SITE:
9365 if r2eff_estimate == 'direct':
9366 self.assertAlmostEqual(value, 0.94504369, 6)
9367 elif r2eff_estimate == 'MC2000':
9368 self.assertAlmostEqual(value, 0.94496541, 6)
9369 elif r2eff_estimate == 'chi2_pyt':
9370 self.assertAlmostEqual(value, 0.92084707, 6)
9371
9372 elif param == 'dw':
9373 if model == MODEL_TP02:
9374 if r2eff_estimate == 'direct':
9375 self.assertAlmostEqual(value, 1.08875840, 6)
9376 elif r2eff_estimate == 'MC2000':
9377 self.assertAlmostEqual(value, 1.08765638, 6)
9378 elif r2eff_estimate == 'chi2_pyt':
9379 self.assertAlmostEqual(value, 1.09753230, 6)
9380 elif model == MODEL_TAP03:
9381 if r2eff_estimate == 'direct':
9382 self.assertAlmostEqual(value, 1.08837238, 6)
9383 elif r2eff_estimate == 'MC2000':
9384 self.assertAlmostEqual(value, 1.08726698, 6)
9385 elif r2eff_estimate == 'chi2_pyt':
9386 self.assertAlmostEqual(value, 1.09708821, 6)
9387 elif model == MODEL_MP05:
9388 if r2eff_estimate == 'direct':
9389 self.assertAlmostEqual(value, 1.08837241, 6)
9390 elif r2eff_estimate == 'MC2000':
9391 self.assertAlmostEqual(value, 1.08726706, 6)
9392 elif r2eff_estimate == 'chi2_pyt':
9393 self.assertAlmostEqual(value, 1.09708832, 6)
9394 elif model == MODEL_NS_R1RHO_2SITE:
9395 if r2eff_estimate == 'direct':
9396 self.assertAlmostEqual(value, 1.56001812, 5)
9397 elif r2eff_estimate == 'MC2000':
9398 self.assertAlmostEqual(value, 1.55833321, 5)
9399 elif r2eff_estimate == 'chi2_pyt':
9400 self.assertAlmostEqual(value, 1.36406712, 5)
9401
9402 elif param == 'kex':
9403 if model == MODEL_DPL94:
9404 if r2eff_estimate == 'direct':
9405 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7)
9406 elif r2eff_estimate == 'MC2000':
9407 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7)
9408 elif r2eff_estimate == 'chi2_pyt':
9409 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7)
9410 elif model == MODEL_TP02:
9411 if r2eff_estimate == 'direct':
9412 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7)
9413 elif r2eff_estimate == 'MC2000':
9414 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7)
9415 elif r2eff_estimate == 'chi2_pyt':
9416 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7)
9417 elif model == MODEL_TAP03:
9418 if r2eff_estimate == 'direct':
9419 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7)
9420 elif r2eff_estimate == 'MC2000':
9421 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7)
9422 elif r2eff_estimate == 'chi2_pyt':
9423 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7)
9424 elif model == MODEL_MP05:
9425 if r2eff_estimate == 'direct':
9426 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7)
9427 elif r2eff_estimate == 'MC2000':
9428 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7)
9429 elif r2eff_estimate == 'chi2_pyt':
9430 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7)
9431 elif model == MODEL_NS_R1RHO_2SITE:
9432 if r2eff_estimate == 'direct':
9433 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6)
9434 elif r2eff_estimate == 'MC2000':
9435 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6)
9436 elif r2eff_estimate == 'chi2_pyt':
9437 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6)
9438
9439 elif param == 'chi2':
9440 if model == MODEL_NOREX:
9441 if r2eff_estimate == 'direct':
9442 self.assertAlmostEqual(value, 848.42016907, 5)
9443 elif r2eff_estimate == 'MC2000':
9444 self.assertAlmostEqual(value, 3363.95829122, 5)
9445 elif r2eff_estimate == 'chi2_pyt':
9446 self.assertAlmostEqual(value, 5976.49946726, 5)
9447 elif model == MODEL_DPL94:
9448 if r2eff_estimate == 'direct':
9449 self.assertAlmostEqual(value, 179.47041241)
9450 elif r2eff_estimate == 'MC2000':
9451 self.assertAlmostEqual(value, 710.24767560)
9452 elif r2eff_estimate == 'chi2_pyt':
9453 self.assertAlmostEqual(value, 612.72616697, 5)
9454 elif model == MODEL_TP02:
9455 if r2eff_estimate == 'direct':
9456 self.assertAlmostEqual(value, 29.33882530, 6)
9457 elif r2eff_estimate == 'MC2000':
9458 self.assertAlmostEqual(value, 114.47142772, 6)
9459 elif r2eff_estimate == 'chi2_pyt':
9460 self.assertAlmostEqual(value, 250.50838162, 5)
9461 elif model == MODEL_TAP03:
9462 if r2eff_estimate == 'direct':
9463 self.assertAlmostEqual(value, 29.29050673, 6)
9464 elif r2eff_estimate == 'MC2000':
9465 self.assertAlmostEqual(value, 114.27987534)
9466 elif r2eff_estimate == 'chi2_pyt':
9467 self.assertAlmostEqual(value, 250.04050719, 5)
9468 elif model == MODEL_MP05:
9469 if r2eff_estimate == 'direct':
9470 self.assertAlmostEqual(value, 29.29054301, 6)
9471 elif r2eff_estimate == 'MC2000':
9472 self.assertAlmostEqual(value, 114.28002272)
9473 elif r2eff_estimate == 'chi2_pyt':
9474 self.assertAlmostEqual(value, 250.04077478, 5)
9475 elif model == MODEL_NS_R1RHO_2SITE:
9476 if r2eff_estimate == 'direct':
9477 self.assertAlmostEqual(value, 34.44010543, 6)
9478 elif r2eff_estimate == 'MC2000':
9479 self.assertAlmostEqual(value, 134.14368365)
9480 elif r2eff_estimate == 'chi2_pyt':
9481 self.assertAlmostEqual(value, 278.55121388, 5)
9482
9483
9484
9485 model = 'final'
9486 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model))
9487 print("\nFinal pipe")
9488
9489
9490 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9491
9492 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
9493
9494
9495 print("Optimised model for spin: %s" % (spin_string))
9496 param = 'model'
9497
9498
9499 value = getattr(cur_spin, param)
9500 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value))
9501
9502
9503
9504 file_names = ['r1rho_prime', 'r1']
9505
9506 for file_name_i in file_names:
9507
9508
9509 file_name = "%s.out" % file_name_i
9510
9511
9512 file_path = get_file_path(file_name, result_dir_name + sep + model)
9513
9514
9515 print("Testing file access to: %s"%file_path)
9516 self.assert_(access(file_path, F_OK))
9517
9518
9519 file_prod = open(file_path)
9520 lines_prod = file_prod.readlines()
9521 file_prod.close()
9522
9523
9524 for i, line in enumerate(lines_prod):
9525
9526 line_split = line.split()
9527
9528
9529 if line_split[0] == "#":
9530 print(line),
9531 continue
9532
9533
9534 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split
9535 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error)
9536
9537 if res_num == '52':
9538
9539 self.assertNotEqual(val, 'None')
9540